How to make a single label per category in legend for subplots?

Hi!
I have 5 subplots (different calculations made per date for each category)
What I want is to have only one label per each category in the legend (not 5)
Can someone suggest to me how can I achieve that result, please?

Here is the code snippet I used to generate the chart and a part of it to understand how it looks like(I sketched real categories` names)

colors = [
    '#1f77b4',  # muted blue
    '#ff7f0e',  # safety orange
    '#2ca02c',  # cooked asparagus green
    '#d62728',  # brick red
    '#9467bd',  # muted purple
    '#8c564b',  # chestnut brown
    '#e377c2',  # raspberry yogurt pink
    '#7f7f7f',  # middle gray
    '#bcbd22',  # curry yellow-green
    '#17becf',   # blue-teal,
    '#cab2cf', #light purple
    '#292e28', #black-gray
    '#785b7d', # dirty purple
]

fig = make_subplots(rows=5, cols=1, start_cell="top-left", subplot_titles  = stats_df.columns[2:] )
i = 0
for s in stats_df.columns[2:]:
  for k, c in enumerate(names_df['cat_name']):
    fig.add_trace(
        go.Scatter(
            x=stats_df.loc[stats_df['cat_name'] == c,:]['created_at'],
            y=stats_df.loc[stats_df['cat_name'] == c,:][s],
            name=c,
            mode='lines+markers',
            marker=dict(
                color=colors[k], 
                line=dict(
                    color=colors[k]
                )
            ),
            legendgroup=c
        ),
        row = i + 1,
        col = 1

    )
  i += 1

fig.update_layout(hovermode="x", plot_bgcolor = 'rgba(0,0,0,0)', width = 1000, height = 1700 )

You could simply add the following in your Scatters:

showlegend=(i==0)
1 Like

Thank you very much, it worked!