您应该能够使用 update_xaxes
方法从一个图形对象更新您的x轴:
fig = px.bar(stacked_ratio, y="percent", x="team", color="outcome",
color_discrete_map=colors, title="Long-Form Input")
fig.update_xaxes(tickangle=90)
fig.show()
您可以在此处的Plotly网站上查看有关fig.update_xaxes
的所有选项:https://plotly.com/python/reference/layout/xaxis/
你好,在另一个论坛上找到了这段代码,对我很有效。希望这能帮到你!
fig.update_xaxes(tickangle= -90)
fig.show()
Tickangle=90
表示标签将顺时针旋转90度。如果使用负号,您可以逆时针旋转标签90度,即向另一个方向。
tickangle = 45
,但这只是个人口味问题。 - rocarvaj