Multiple traces with same names but different legend

Can multple traces have the same name, but have different color on graph and in legend?

Yes, did you try it?

import plotly.graph_objects as go
import numpy as np

def data():
    return np.random.randint(0, 255, 10)

fig = go.Figure()
traces = [go.Scatter(x=data(), y=data(), name='the_name', mode='markers', marker={'color': color}) for color in ['red', 'green', 'blue']]

fig.update_layout(width=500, height=500)


1 Like

yes, but thanks. I had a mistake in my code and i noticed it only after posting question. thanks.

I would like to do the opposite: multiple traces have the same name and have the same color and name on the graph and in legend. Is it possible to do that?

Hey @Friburg, welcome to the forums!

Iā€™m not sure I understood what you want to do. Could you perhaps add some more information?