-
-
Notifications
You must be signed in to change notification settings - Fork 11
Add consistent legend support across backends #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""None backend manual legend generation. | ||
|
||
For now only used for documentation purposes. | ||
""" | ||
|
||
|
||
# pylint: disable=unused-argument | ||
def legend( | ||
target, kwarg_list, label_list, title=None, artist_type="line", artist_kwargs=None, **kwargs | ||
): | ||
"""Generate a legend on a figure given lists of labels and property kwargs. | ||
|
||
Parameters | ||
---------- | ||
target : plot object | ||
kwarg_list : sequence of mapping | ||
label_list : sequence of str | ||
title : str, optional | ||
artist_type : {"line", "scatter", "rectangle"}, default "line" | ||
artist_kwargs : mapping, optional | ||
Passed to all artists when generating legend miniatures. | ||
**kwargs | ||
Passed to backend legend generating function. | ||
""" | ||
return None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,58 @@ | ||
"""Plotly legend generation.""" | ||
|
||
|
||
def dealiase_line_kwargs(kwargs): | ||
"""Convert arviz common interface properties to plotly ones.""" | ||
prop_map = {"linewidth": "width", "linestyle": "dash"} | ||
return {prop_map.get(key, key): value for key, value in kwargs.items()} | ||
|
||
|
||
def legend( | ||
target, kwarg_list, label_list, title=None, artist_type="line", artist_kwargs=None, **kwargs | ||
): | ||
"""Generate a legend with plotly.""" | ||
raise NotImplementedError("Still in progress") | ||
"""Generate a legend with plotly. | ||
amaloney marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Parameters | ||
---------- | ||
target : plotly.graph_objects.Figure | ||
The figure to add the legend to | ||
kwarg_list : list | ||
List of style dictionaries for each legend entry | ||
label_list : list | ||
List of labels for each legend entry | ||
title : str, optional | ||
Title of the legend | ||
artist_type : str, optional | ||
Type of artist to use for legend entries. Currently only "line" is supported. | ||
artist_kwargs : dict, optional | ||
Additional kwargs passed to all artists | ||
**kwargs : dict | ||
Additional kwargs passed to legend configuration | ||
|
||
Returns | ||
------- | ||
None | ||
The legend is added to the target figure inplace | ||
""" | ||
if artist_kwargs is None: | ||
artist_kwargs = {} | ||
|
||
if artist_type == "line": | ||
artist_fun = target.add_scatter | ||
kwarg_list = [dealiase_line_kwargs(kws) for kws in kwarg_list] | ||
Advaitgaur004 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mode = "lines" | ||
else: | ||
raise NotImplementedError("Only line type legends supported for now") | ||
|
||
for kws, label in zip(kwarg_list, label_list): | ||
artist_fun( | ||
x=[None], | ||
y=[None], | ||
name=str(label), | ||
mode=mode, | ||
line=kws, | ||
showlegend=True, | ||
**artist_kwargs, | ||
) | ||
|
||
target.update_layout(showlegend=True, legend_title_text=title, **kwargs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.