You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Doc]: Use tick_params() instead of iterating over tick labels for setting tick properties #23372
for label in ax.get_xticklabels():
label.set_rotation(90)
look similar.
However, the first solution is to be preferred:
It's shorter.
There's a fundamental difference: Tick label instances are not stable. They may be deleted, moved around or new ones created, e.g. when you pan or zoom the plot.(1) affects all current tick labels and sets the default for future ones. (2) only modifies the current labels. That means you can get labels with a different style when you manipulate the figure. This is almost never wanted. Therefore (2) is discouraged and we should remove it from our examples.
Suggested improvement
Search through the examples and tutorials files. Suggest regular expression in.*ticklabels\(\)
Replace the for loop with a call to tick_params(). (Note: Not every property of ticks is accessible through tick_params() so there may be some rare cases that cannot be replaced as of now.)
Validate visually that the old and new code produce the same figure.
Also, many of these calls set rotation, and then also horizontalalignment, but I don't think we expose that via tick_params, so this is somewhat contingent on #20644
Activity
QuLogic commentedon Jun 30, 2022
Possibly also iteration over
Axis.get_major_ticksandAxes.get_minor_ticksshould be changed as well.QuLogic commentedon Jun 30, 2022
Also, many of these calls set
rotation, and then alsohorizontalalignment, but I don't think we expose that viatick_params, so this is somewhat contingent on #20644Use tick_params more often over tick iteration
Use tick_params more often over tick iteration
timhoffm commentedon Jul 1, 2022
Simple cases fixed by #23377.
waiting for #20644
timhoffm commentedon Nov 3, 2025
There's still need for improvement in the docs at least at:
Overall, the artist tutorial should mention that ticks are ephemal and thus any applied properties may vanish.
Also all getter methods for sequences of tick components should get an appropirate note.
Use tick_params more often over tick iteration