question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Per-group (e.g. legendgroup) trace styling

See original GitHub issue

If 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)

newplot-12

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:open
  • Created 5 years ago
  • Reactions:18
  • Comments:17 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
alexcjohnsoncommented, Jun 19, 2018

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 need sharelegendgroupstyle), 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.

6reactions
bodacious-billcommented, Jan 18, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found