Plotly:不使用plotly express时如何为散布痕迹设置标题颜色?

问题描述 投票:0回答:1

当我做这样的散点图时:

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一样?

enter image description here

python plotly
1个回答
0
投票

您可以通过fig.update(legend_title=dict(font=dict(color='Blue')))编辑字体颜色,字号等:

enter image description here

完整代码:

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()
© www.soinside.com 2019 - 2024. All rights reserved.