1 回答

TA贡献1828条经验 获得超3个赞
答案:
您可以使用:
fig.for_each_xaxis(lambda axis: axis.title.update(font=dict(color = 'blue', size=20)))
一些细节:
基于plotly 文档中的子图示例,以下代码片段...
fig.for_each_xaxis(lambda axis: axis.title.update(font=dict(size=24))) fig.for_each_yaxis(lambda axis: axis.title.update(font=dict(size=24)))
...将改变这个:
...进入这个:
完整代码:
from plotly.subplots import make_subplots
import plotly.graph_objects as go
# Initialize figure with subplots
fig = make_subplots(
rows=2, cols=2, subplot_titles=("Plot 1", "Plot 2", "Plot 3", "Plot 4")
)
# Add traces
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1)
fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2)
fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1)
fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2)
# Update xaxis properties
fig.update_xaxes(title_text="xaxis 1 title", row=1, col=1)
fig.update_xaxes(title_text="xaxis 2 title", range=[10, 50], row=1, col=2)
fig.update_xaxes(title_text="xaxis 3 title", showgrid=False, row=2, col=1)
fig.update_xaxes(title_text="xaxis 4 title", type="log", row=2, col=2)
# Update yaxis properties
fig.update_yaxes(title_text="yaxis 1 title", row=1, col=1)
fig.update_yaxes(title_text="yaxis 2 title", range=[40, 80], row=1, col=2)
fig.update_yaxes(title_text="yaxis 3 title", showgrid=False, row=2, col=1)
fig.update_yaxes(title_text="yaxis 4 title", row=2, col=2)
# Update title and height
fig.update_layout(title_text="Customizing Subplot Axes", height=700)
# change subplot axes font size
fig.for_each_xaxis(lambda axis: axis.title.update(font=dict(color = 'blue', size=20)))
fig.for_each_yaxis(lambda axis: axis.title.update(font=dict(color = 'blue', size=20)))
fig.show()
添加回答
举报