Per-group (e.g. legendgroup) trace styling
See original GitHub issueIf I want two traces on two sub-plots to share the same legend, I (think I) have to explicitly specify the trace color, like
import plotly.graph_objs as go
from plotly.offline import iplot, init_notebook_mode
init_notebook_mode()
style1 = dict(name='trace1', legendgroup='trace1', line=dict(color='red'))
style2 = dict(name='trace2', legendgroup='trace2', line=dict(color='blue'))
fig = go.Figure(
data=[dict(y=[1, 2, 3], **style1),
dict(y=[2, 1, 3], **style2),
dict(y=[1, 2, 3], showlegend=False, xaxis='x2', **style1),
dict(y=[1, 3, 2.5], showlegend=False, xaxis='x2', **style2)],
layout=dict(xaxis=dict(domain=[0, .45]),
xaxis2=dict(domain=[.55, 1]))
)
iplot(fig)
One issue with the above is that I lose the default plotly colors (see https://github.com/plotly/plotly.py/issues/1026 for getting them back).
Is there a more generic way to tell plotly that two traces should share the same legend/style, or even count as one? Thanks
Issue Analytics
- State:
- Created 5 years ago
- Reactions:18
- Comments:17 (3 by maintainers)
Top Results From Across the Web
How to link plotly traces for legend and colour selection?
1. There's a legendgroup attribute that could let you do what you want, but only if you plot each group separately (8 traces,...
Read more >Legends in Python - Plotly
Grouping legend items together by setting the legendgroup attribute of traces causes their legend entries to be next to each other, and clicking...
Read more >greykite.common.viz.timeseries_plotting - LinkedIn Open Source
"time" in our example. y_col_style_dict: `dict` [`str`, `dict` or None] The column(s) to plot on the y-axis, and how to style them.
Read more >tidyverse, plotly Flashcards - Quizlet
read_log # read_log() reads Apache style log files. ... Traces are categorized by chart type (e.g. scatter, heatmap). ... legendgroup. Type: string
Read more >Create Interactive Web Graphics via 'plotly.js'
a plotly visualization data a data frame. Examples plot_ly() %>% add_data(economics) %>% add_trace(x = ~date, y = ~pce) ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You’re correct, that ability doesn’t exist today. I like the idea, and in v2 we could consider making this the default behavior, but for now it would need to be opt-in. Something like
sharegroupstyle: true
(though we have other kinds of groups too, it’s getting a bit long but we may needsharelegendgroupstyle
), would make this trace inherit style attributes from the first trace in the legend group before applying its own values. I’m a little uneasy with the order-dependence of that, could have some unexpected consequences upon reordering or adding/removing traces (and we’ll have to be careful how it behaves on hiding/showing traces) but I think we can sort that out.Created a github account just to pile on.
The way plotly currently works for this issue goes against the expected behavior, compared to most other common statistical / graphing programs I’ve used. Grouped legends is a crutch, but then manually setting colors and setting showlegend to false for an arbitrary number of traces becomes programmatically cumbersome. This is a major hassle when programming a dashboard for even simple data.