如何以plotly方式旋转xtick标签条形图?

Mar*_*arc 16 python plotly

如何在 Plotly Express 上将团队名称(x 轴)旋转到 90\xc2\xb0?它们没有以正确的方式转动。

\n

这是我的代码。

\n
fig = px.bar(stacked_ratio, y="percent", x="team", color="outcome", \n             color_discrete_map=colors, title="Long-Form Input")\nfig.show()\n
Run Code Online (Sandbox Code Playgroud)\n

其外观如下:\n在此输入图像描述

\n

Cam*_*ell 29

您应该能够使用以下方法从图形对象更新 x 轴update_xaxes

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()
Run Code Online (Sandbox Code Playgroud)

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

  • 我会选择“tickangle = 45”,但这只是一个品味问题。 (2认同)