1

When I do a scatter plot like this:

fig2 = go.Figure()

for num in range(len(dy)):
    data = dz[0:,num]
    fig2.add_trace(go.Scatter(x=dx, y=data, name=str(dy[num]), mode='lines'))

How do I set the color coding title, like when doing color= in plotly.express.line?

enter image description here

vestland
  • 55,229
  • 37
  • 187
  • 305
Invariant
  • 185
  • 1
  • 11

1 Answers1

3

You can edit font color, size and family through fig.update(legend_title=dict(font=dict(color='Blue'))):

enter image description here

Complete code:

import plotly.express as px
import plotly.graph_objects as go

df = px.data.gapminder().query("continent=='Oceania'")

countries = df['country'].unique()
countries

fig2 = go.Figure()
for country in countries:
    df2 = df[df['country']==country]
    fig2.add_traces(go.Scatter(x=df2['year'], y=df2['lifeExp'], name = country,
                              mode='lines',
                              ))

fig2.update_xaxes(title='Year')
fig2.update_yaxes(title='LiefExp')

fig2.update_layout(legend_title=dict(text='Country',
                                     font=dict(family="sans-serif",
                                     size = 18,
                                     color='blue')))


fig2.show()
vestland
  • 55,229
  • 37
  • 187
  • 305