My current code uses a for-loop to populate plotly line plots, generally with hundreds trends being added:
fig.add_trace(go.Scatter(
x=x_axis_data,
y=y_axis_data,
mode='lines',
legendgroup="Data Group 1",
name='Data',
line=dict(
color='royalblue',
dash ='dot',
width=3.5,
)
),row=1,col=j)
Once all of my traces are added, I use the following (which I understand is the default setting anyway):
fig.update_layout(showlegend=True)
My issue is that in the plot legend, I end up with a legend title for every trace when all I want is to show either:
1) unique trace names only (no duplicates), or 2) the legend group name (only 1 time each, not one per trend added).
Is there a way to do this without adding dummy traces, etc.? FYI, I have reviewed the following resource: https://plotly.com/python/legend/. This would work as-is if I was not using a for-loop to populate multiple traces with one fig.add_trace function, but I cannot get it to do what I want with the legend with the for-loop population. Thanks.