Bring Drag & Drop to Dash with Dashboard Engine. 💫 Learn how at our next webinar! difficultly in selecting/ deselecting individual traces for the legend with multiple subplots

Hi, I am having an issue with formatting my legend items with plotly subplots. I have 9 timeseries subplots with each containing three traces. Most of these traces are unique and need to be displayed in the legend, however others are duplicated throughout the subplots and so I would like to only represent them in the legend once.

Unfortunately, I have not been able to find a way for this to work using online examples - most of them rely on using the legendgroup = “xxx” or selectively entering showlegend=False into the appropriate traces, however it seems that using fig = make_subplots (rows = x, cols = y) instead of fig. go Figure() causes both to not be recognised (e.g. “add_trace() got an unexpected keyword argument ‘legendgroup’” ).

I was wondering whether anyone knew of a way to get around this when using subplots? Currently I am defining traces individually i.e.

fig.add_trace(go.Scatter( x=date, y=timeseries1, etc etc)
fig.add_trace(go.Scatter( x=date, y=timeseries2, etc etc)

and the following isn’t recognised by plotly:

  • This example causes an “unexpected keyboard argument error”

fig.add_trace(go.Scatter( x=date, y=timeseries1, showlegend=False)
fig.add_trace(go.Scatter( x=date, y=timeseries2)

  • This example again causes an “unexpected keyboard argument error”

fig.add_trace(go.Scatter( x=date, y=timeseries1, legendgroup=“a”)
fig.add_trace(go.Scatter( x=date, y=timeseries2, legendgroup=“b”)

Any help would be greatly appreciated!