Skip to content

Commit 92f8978

Browse files
committed
Avoid plt.xticks/plt.yticks in gallery examples.
In particular, the ticklabels_rotation example is likely the one most easily found by those looking for how to do this; let's not suggest that plt.xticks is "the" way to rotate ticklabels. Also remove the margins() call (which was really only needed with the old round_numbers autolimits mode) and the subplots_adjust() call (the ticklabels already fit in, and the modern approach would be to use constrained_layout anyways).
1 parent acfef85 commit 92f8978

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

galleries/examples/subplots_axes_and_figures/secondary_axis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def inverse(x):
154154

155155
ax.plot(dates, temperature)
156156
ax.set_ylabel(r'$T\ [^oC]$')
157-
plt.xticks(rotation=70)
157+
ax.xaxis.set_tick_params(rotation=70)
158158

159159

160160
def date2yday(x):

galleries/examples/ticks/ticklabels_rotation.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@
55
66
Demo of custom tick-labels with user-defined rotation.
77
"""
8+
89
import matplotlib.pyplot as plt
910

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

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

0 commit comments

Comments
 (0)