✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

How to add trace name for primary line

Hi All,

The below function merges two graphs also give trace name only for the second line. (added line)
Would liek to know how to add trace name for the base line or primary graph line as well.

fig5 = px.line(df, x = df[‘time’], y = df.columns[3], width=1500, height = 800,title=df.columns[3])
fig5.add_scatter(x=df[‘time’], y=df[df.columns[3]],name=df.columns[3])

Thanks in Advance

Hi @Karthika you can set the name of the trace using fig.update_traces as below

import plotly.express as px
df = px.data.gapminder().query("country == 'Canada'")
fig = px.line(df, x='year', y='lifeExp')
fig.update_traces(showlegend=True, name='lifeExp')
1 Like