Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def inverse(x):

ax.plot(dates, temperature)
ax.set_ylabel(r'$T\ [^oC]$')
plt.xticks(rotation=70)
ax.xaxis.set_tick_params(rotation=70)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm always unsure whether to go through xaxis or ax.tick_params('x', rotation=70). Slight tendency for the higher-level ax.tick_params in simple cases but basically either is fine.



def date2yday(x):
Expand Down
11 changes: 5 additions & 6 deletions galleries/examples/ticks/ticklabels_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@

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

import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y = [1, 4, 9, 6]
labels = ['Frogs', 'Hogs', 'Bogs', 'Slogs']

plt.plot(x, y)
fig, ax = plt.subplots()
ax.plot(x, y)
# You can specify a rotation for the tick labels in degrees or with keywords.
plt.xticks(x, labels, rotation='vertical')
# Pad margins so that markers don't get clipped by the Axes
plt.margins(0.2)
# Tweak spacing to prevent clipping of tick-labels
plt.subplots_adjust(bottom=0.15)
ax.set_xticks(x, labels, rotation='vertical')

plt.show()