# How to remove duplicated legends for the same legend for plotly subplots?

**URL:** <https://community.plotly.com/t/how-to-remove-duplicated-legends-for-the-same-legend-for-plotly-subplots/93265>\
**Category:** 📊 Plotly Python\
**Tags:** question\
**Created:** [July 21, 2025, 5:17pm UTC](https://community.plotly.com/t/how-to-remove-duplicated-legends-for-the-same-legend-for-plotly-subplots/93265 "2025-07-21T17:17:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lei\_Huang](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/lei_huang/32/32248_2.png) [@Lei\_Huang](https://community.plotly.com/u/Lei_Huang)\
**Post date:** [July 21, 2025, 5:17pm UTC](https://community.plotly.com/t/how-to-remove-duplicated-legends-for-the-same-legend-for-plotly-subplots/93265/1 "2025-07-21T17:17:04Z")

</div>

Here is the replication code:

```auto
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import pandas as pd

fig = make_subplots(
    rows=1, cols=2,
    subplot_titles=('Fig1', 'Fig2')
)

df = pd.DataFrame({
    'x': [1, 2, 3, 4, 5],
    'y1': [2, 4, 6, 8, 10],
    'y2': [3, 5, 7, 9, 11]
})

color = {"y1": "blue", "y2": "red"}

fig.add_trace(
    go.Scatter(x=df['x'], y=df['y1'], mode='lines+markers', name='y1', line=dict(color=color['y1'])),
    row=1, col=1
)

fig.add_trace(
    go.Scatter(x=df['x'], y=df['y2'], mode='lines+markers', name='y2', line=dict(color=color['y2'])),
    row=1, col=1
)

fig.add_trace(
    go.Scatter(x=df['x'], y=df['y1'], mode='lines+markers', name='y1', line=dict(color=color['y1'])),
    row=1, col=2
)

fig.add_trace(
    go.Scatter(x=df['x'], y=df['y2'], mode='lines+markers', name='y2', line=dict(color=color['y2'])),
    row=1, col=2
)

fig.show()

```

Here is the output figure:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/9/8/984548daa0768eb0cfa140e0ffdd858504217738.png)

We can see the legend that there are duplicates! Legend for y1 and y2 are the same in these two subplots therefore they should appear once. How to avoid such duplicates? i.e. I should have the following legend:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/f/c/fc96118025e4daeb6320e18622e8d9a7f0656f03.png)

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [July 21, 2025, 9:54pm UTC](https://community.plotly.com/t/how-to-remove-duplicated-legends-for-the-same-legend-for-plotly-subplots/93265/2 "2025-07-21T21:54:06Z")

</div>

I think you can set showlegend=False for the last two traces.

---

<div class="post-metadata">

**Author:** ![Lei\_Huang](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/lei_huang/32/32248_2.png) [@Lei\_Huang](https://community.plotly.com/u/Lei_Huang)\
**Post date:** [July 22, 2025, 1:21am UTC](https://community.plotly.com/t/how-to-remove-duplicated-legends-for-the-same-legend-for-plotly-subplots/93265/3 "2025-07-22T01:21:25Z")

</div>

Great idea. Thx.
