要修改Plotly图表的字体和颜色,可以使用layout属性和trace属性来自定义图表的样式。
import plotly.graph_objects as go
fig = go.Figure(data=go.Scatter(x=[1, 2, 3], y=[4, 1, 2]))
fig.update_layout(
title_text = "Customizing Fonts",
title_font = dict(
family="Arial",
size=20,
color="blue"
),
xaxis=dict(
title_text="X Axis",
title_font=dict(
family="Arial",
size=12,
color="red"
)
),
yaxis=dict(
title_text="Y Axis",
title_font=dict(
family="Arial",
size=12,
color="green"
)
),
legend=dict(
font=dict(
family="Arial",
size=10,
color="black"
)
)
)
fig.show()
import plotly.graph_objects as go
fig = go.Figure(data=go.Scatter(x=[1, 2, 3], y=[4, 1, 2], mode='lines+markers'))
fig.update_traces(
marker=dict(
color='red'
),
line=dict(
color='blue'
)
)
fig.show()
通过这些方式,可以轻松地修改Plotly图表的字体和颜色,使其更符合自己的需求和风格。