Skip to content

Expand ticklabels_rotation example to cover rotating default ticklabels. #28455

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Changes from all 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
25 changes: 19 additions & 6 deletions galleries/examples/ticks/ticklabels_rotation.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""
===========================
Rotating custom tick labels
===========================

Demo of custom tick-labels with user-defined rotation.
====================
Rotating tick labels
====================
"""

import matplotlib.pyplot as plt
Expand All @@ -14,7 +12,22 @@

fig, ax = plt.subplots()
ax.plot(x, y)
# You can specify a rotation for the tick labels in degrees or with keywords.
# A tick label rotation can be set using Axes.tick_params.
ax.tick_params("y", rotation=45)
# Alternatively, if setting custom labels with set_xticks/set_yticks, it can
# be set at the same time as the labels.
# For both APIs, the rotation can be an angle in degrees, or one of the strings
# "horizontal" or "vertical".
ax.set_xticks(x, labels, rotation='vertical')

plt.show()

# %%
#
# .. admonition:: References
#
# The use of the following functions, methods, classes and modules is shown
# in this example:
#
# - `matplotlib.axes.Axes.tick_params` / `matplotlib.pyplot.tick_params`
# - `matplotlib.axes.Axes.set_xticks` / `matplotlib.pyplot.xticks`