matplotlib / cheatsheets

Official Matplotlib cheat sheets

Home Page:https://matplotlib.org/cheatsheets/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A better answer about "How I rotate tick labels"

camel712 opened this issue · comments

The cheatsheets comment the method "ax.set_[xy]ticks(rotation=90)" to rotate ticks. However, it can cause confusion because the parameter "takes effect only if you pass labels"(official tutorial of ax.set_[xy]ticks(). So this is a incomplete form and not recommended.
As the official tutorial says, I suggest ax.tick_params(axis='x', rotation=90).

Thanks for the report. Do you have a link to this part of the documentation?

See the kwargs description of https://matplotlib.org/stable/api/_as_gen/matplotlib.axis.Axis.set_xticks.html#matplotlib.axis.Axis.set_xticks

The parameters are only applied to ticks instances generated in this function. It does not affect the global setting for default tick params.

plt.xticks(rotation=90) tries to behave slightly better by updating existing ticks. But that's still different from changing the default and can lead to surprising results #22521. Unfortunately the topic of ticks is quite involved and it's a bit difficult to improve on that. For the time being tick_params() is really the best and recommended option.

@timhoffm Thanks for the explanation.
@camel712 Could you make a PR?