首页 > 解决方案 > 如何旋转 xtick 标签条形图 plotly express?

问题描述

如何将 Plotly express 上的团队名称(x 轴)旋转 90°?他们没有以正确的方式转向。

这是我的代码。

fig = px.bar(stacked_ratio, y="percent", x="team", color="outcome", 
             color_discrete_map=colors, title="Long-Form Input")
fig.show()

它的外观如下: 在此处输入图像描述

标签: pythonplotly

解决方案


您应该能够使用以下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()

您可以fig.update_xaxes在此处查看 plotly 网站上的所有选项:https ://plotly.com/python/reference/layout/xaxis/


推荐阅读