How to Rotate Xtick Label Bar Chart Plotly Express?

How can I rotate to 90° the team names (x-axis) on Plotly express? They are not turned in the right way.

Here is my code.

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

Here how it looks:

3 Answers

You should be able to update your x-axis from a figure object with the update_xaxes method:

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()

You can see all options for fig.update_xaxes on the plotly website here:

1

Hi found this piece of code in another forum, it worked for me. Hope this helps!


fig.update_xaxes(tickangle= -90)  
fig.show()
1

Tickangle=90 means that the labels will be rotated by 90° clockwise. If you use the negative sign, you rotate the labels by 90° anti-clockwise, so just the other direction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest