要修改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圖表的字體和顏色,使其更符合自己的需求和風格。