cheatsheets icon indicating copy to clipboard operation
cheatsheets copied to clipboard

A better answer about "How I rotate tick labels"

Open camel712 opened this issue 2 years ago • 3 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).

camel712 avatar Apr 28 '22 16:04 camel712

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

rougier avatar Apr 29 '22 08:04 rougier

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 avatar Apr 29 '22 11:04 timhoffm

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

rougier avatar Apr 29 '22 18:04 rougier