| [ Web Proxy ] |
| Viewing: https://matplotlib.org/gallery/mplot3d/../ticks/align_ticklabels.html | [Back] [Original] |
Section Navigation
fill_between with transparencyhisttype settingsplt.subplotsfloating_axes featuresNote
Go to the end to download the full example code.
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.
[align ticklabels]import matplotlib.pyplot as plt
population = {
"Sydney": 5.2,
"Mexico City": 8.8,
"So 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)
Copyright 20022012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 20122026 The Matplotlib development team.
Created using Sphinx 9.1.0.
Built from v3.11.2-1-g879ad8ebba.
Built with the PyData Sphinx Theme 0.16.1.
| Web Proxy Viewer | New URL | Original Page |