| [ Web Proxy ] |
| Viewing: https://matplotlib.org/gallery/mplot3d/../user_interfaces/../misc/../ticks/ticklabels_rotation.html | [Back] [Original] |
Section Navigation
fill_between with transparencyhisttype settingsplt.subplotsfloating_axes featuresNote
Go to the end to download the full example code.
Rotating tick labels can be useful when the labels are long and overlap with each other.
Adjust the tick properties using tick_params: Set the angle in degrees via
the rotation parameter. Set the rotation_mode parameter to "xtick" / "ytick" to
make the text point towards the tick, see also set_rotation_mode.
Note: We use layout="constrained" to make sure there is enough space for the tick
labels so that they are not cut off.
import matplotlib.pyplot as plt
population = {
'India': 1417.492,
'China': 1404.89,
'United States': 341.784857,
'Indonesia': 284.438782,
'Pakistan': 241.499431,
'Nigeria': 223.8,
'Brazil': 213.421037,
'Bangladesh': 169.828911,
'Russia': 146.028325,
'Mexico': 131.001723,
'Japan': 122.95,
'Philippines': 114.1236,
'DR Congo': 112.832,
'Ethiopia': 111.652998,
'Egypt': 107.868296,
'Vietnam': 102.3,
}
fig, ax = plt.subplots(layout="constrained")
ax.bar(population.keys(), population.values())
ax.tick_params("x", rotation=45, rotation_mode="xtick")
ax.set_ylabel("population (millions)")
plt.show()
[ticklabels rotation]References
The use of the following functions, methods, classes and modules is shown in this example:
Tags: component: ticks plot-type: bar
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 |