How can I avoid duplicate legend labels in subplots? One way I would go about it in matplotlib would be to pass custom legend labels to an legend object. I couldn\'t find an
A better way:
Set the legendgroup
option to the legend label you want for each trace.
This will allow you to filter everything in the same group.
Hide the remaining traces' legends using the showlegend=False
option.
This will give the exact behaviour you want.
Old Solution (Not recommended):
There is a another solution by adding "dummy" traces and hiding the data but only showing the legend. With this method you cannot slice any of the data (which is not a bad thing).
trace_dummy = Scatter(
x=[0, 0, 0], # Data is irrelevant since it won't be shown
y=[0, 0, 0],
name='Whatever Trace',
showlegend=True,
visible="legendonly"
)