Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Doc]: Use tick_params() instead of iterating over tick labels for setting tick properties #23372

Open
@timhoffm

Description

@timhoffm

Documentation Link

No response

Problem

At first sight, the effects of (1)

ax.tick_params(axis='x', labelrotation=90)

and (2)

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

  1. Search through theexamples andtutorials files. Suggest regular expressionin.*ticklabels\(\)
  2. Replace thefor loop with a call totick_params(). (Note: Not every property of ticks is accessible throughtick_params() so there may be some rare cases that cannot be replaced as of now.)
  3. Validate visually that the old and new code produce the same figure.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp