Skip to content

single legend for multiple traces / share legend across subplots / disable automatic mapping of fill, color, etc #800

Closed
@rubenalv

Description

@rubenalv

Hello,
I am not sure whether this is a bug or a feature to request, perhaps it's in between.

the problems: mapping of data to the legend seems automatic and cannot be disabled. If traces share names (I think) they should be plotted with a unique legend name and not with one name per trace, repeating the names.

example:
I have a plot with a legend with two elements: 'name': 'trace1' and 'name':'trace2' but four actual traces, which I divide in two groups by marker symbol. The result is a plot per trace (correct), mapping of legend to both color and symbol (not desired), and repeated trace names in the legend (I would like the trace names to show as unique names).

expected behaviour: No automatic mapping, the user can decide whether to map or not (e.g. ggplot2 from R does this. E.g. with 'color', if it is within an aesthetic group it's mapped, but when it is outside that group it is fixed and does not appear in the legend). Since two traces share a name, they should be mapped to a single name in the legend, and when clicking on that name both traces should get hidden.

suggested workarounds: Hide some legend names. However this is not good, because if the legend is hidden the traces cannot be accessed from it. I expect that a unique legend name controls more than one trace in the plot.

example code:

import plotly.offline as pyoff

dataplot = [
  dict(
   name = 'trace1',
   x = [1,2,3,4],
   y = [1,1,1,1],
   mode = 'markers',
   marker = {'symbol':'circle'}),
  dict(
   name = 'trace2',
   x = [1,2,3,4],
   y = [2,2,2,2],
   mode = 'markers',
   marker = {'symbol':'circle'}),
  dict(
   name = 'trace1',
   x = [1,2,3,4],
   y = [3,3,3,3],
   mode = 'markers',
   marker = {'symbol':'square'}),
  dict(
   name = 'trace2',
   x = [1,2,3,4],
   y = [4,4,4,4],
   mode = 'markers',
   marker = {'symbol':'square'})
  ]

pyoff.plot(dict(data = dataplot))
   

Thank you very much for all contributions, I wished I knew enough to help myself!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions