当我做这样的散点图时:
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'))
如何设置颜色编码标题,就像在color=
中进行plotly.express.line
一样?
您可以通过fig.update(legend_title=dict(font=dict(color='Blue')))
编辑字体颜色,字号等:
完整代码:
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()