Plotly python与子地块共享x轴,不能使用后缀

2024-10-05 14:21:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我的问题是,当我用子地块创建多个绘图时,x_轴是共享的,x_轴上的后缀不会显示

我使用的代码是:

import plotly.graph_objects as go

fig = make_subplots(rows=2, cols=1, shared_xaxes=True, vertical_spacing=0.05)

fig.add_trace(
go.Bar(x=[1, 2, 3], y=[4, 5, 6]),
row=1, col=1
)

fig.add_trace(
go.Bar(x=[2, 3, 4], y=[5, 6, 7]),
row=2, col=1
)

fig.update_layout(height=600, width=800, title_text=“Subplots”, xaxis=dict(ticksuffix="%"))
fig.show()

有谁能帮忙,我做错了什么

提前谢谢


Tags: 代码importaddgo绘图figtracebar
1条回答
网友
1楼 · 发布于 2024-10-05 14:21:51

你的目标图是这样的吗

import plotly.graph_objects as go
from plotly.subplots import make_subplots

fig = make_subplots(rows=2, cols=1, shared_xaxes=True, vertical_spacing=0.05)

fig.add_trace(
go.Bar(x=[1, 2, 3], y=[4, 5, 6]),
row=1, col=1
)

fig.add_trace(
go.Bar(x=[2, 3, 4], y=[5, 6, 7]),
row=2, col=1
)

fig.update_layout(height=600, width=800, title_text='Subplots')
fig.update_xaxes(dict(ticksuffix="%"))
fig.show()

相关问题 更多 >