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

Backport PR #30763 on branch v3.10.x (DOC: Add example how to align tick labels)#30801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletionsgalleries/examples/ticks/align_ticklabels.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
"""
=================
Align tick labels
=================

By default, tick labels are aligned towards the axis. This means the set of
*y* tick labels appear right-aligned. Because the alignment reference point
is on the axis, left-aligned tick labels would overlap the plotting area.
To achieve a good-looking left-alignment, you have to additionally increase
the padding.
"""
import matplotlib.pyplot as plt

population = {
"Sydney": 5.2,
"Mexico City": 8.8,
"São Paulo": 12.2,
"Istanbul": 15.9,
"Lagos": 15.9,
"Shanghai": 21.9,
}

fig, ax = plt.subplots(layout="constrained")
ax.barh(population.keys(), population.values())
ax.set_xlabel('Population (in millions)')

# left-align all ticklabels
for ticklabel in ax.get_yticklabels():
ticklabel.set_horizontalalignment("left")

# increase padding
ax.tick_params("y", pad=70)

[8]ページ先頭

©2009-2025 Movatter.jp