Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ae9404c

Browse files
committed
Fix tick_params() label rotation mode
Follow-up to matplotlib#28968. The rotation_mode was only wired up half way, so that the parameter was accepted but did not have any effect.
1 parent 2ab27cd commit ae9404c

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

‎lib/matplotlib/axes/_base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3469,7 +3469,9 @@ def tick_params(self, axis='both', **kwargs):
34693469
labelbottom, labeltop, labelleft, labelright : bool
34703470
Whether to draw the respective tick labels.
34713471
labelrotation : float
3472-
Tick label rotation
3472+
Tick label rotation angle in degrees. See `.Text.set_rotation`.
3473+
labelrotation_mode : {'default', 'anchor', 'xtick', 'ytick'}
3474+
Tick label rotation mode. See `.Text.set_rotation_mode`.
34733475
grid_color : :mpltype:`color`
34743476
Gridline color.
34753477
grid_alpha : float

‎lib/matplotlib/axis.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def __init__(
7575
label2On=False,
7676
major=True,
7777
labelrotation=0,
78+
labelrotation_mode=None,
7879
grid_color=None,
7980
grid_linestyle=None,
8081
grid_linewidth=None,
@@ -157,11 +158,13 @@ def __init__(
157158
self.label1 = mtext.Text(
158159
np.nan, np.nan,
159160
fontsize=labelsize, color=labelcolor, visible=label1On,
160-
fontfamily=labelfontfamily, rotation=self._labelrotation[1])
161+
fontfamily=labelfontfamily, rotation=self._labelrotation[1],
162+
rotation_mode=labelrotation_mode)
161163
self.label2 = mtext.Text(
162164
np.nan, np.nan,
163165
fontsize=labelsize, color=labelcolor, visible=label2On,
164-
fontfamily=labelfontfamily, rotation=self._labelrotation[1])
166+
fontfamily=labelfontfamily, rotation=self._labelrotation[1],
167+
rotation_mode=labelrotation_mode)
165168

166169
self._apply_tickdir(tickdir)
167170

@@ -321,7 +324,8 @@ def _apply_params(self, **kwargs):
321324
self.label2.set(rotation=self._labelrotation[1])
322325

323326
label_kw = {k[5:]: v for k, v in kwargs.items()
324-
if k in ['labelsize', 'labelcolor', 'labelfontfamily']}
327+
if k in ['labelsize', 'labelcolor', 'labelfontfamily',
328+
'labelrotation_mode']}
325329
self.label1.set(**label_kw)
326330
self.label2.set(**label_kw)
327331

@@ -1050,14 +1054,15 @@ def _translate_tick_params(cls, kw, reverse=False):
10501054
'tick1On', 'tick2On', 'label1On', 'label2On',
10511055
'length', 'direction', 'left', 'bottom', 'right', 'top',
10521056
'labelleft', 'labelbottom', 'labelright', 'labeltop',
1053-
'labelrotation', 'rotation_mode',
1057+
'labelrotation', 'labelrotation_mode',
10541058
*_gridline_param_names]
10551059

10561060
keymap = {
10571061
# tick_params key -> axis key
10581062
'length': 'size',
10591063
'direction': 'tickdir',
10601064
'rotation': 'labelrotation',
1065+
'rotation_mode': 'labelrotation_mode',
10611066
'left': 'tick1On',
10621067
'bottom': 'tick1On',
10631068
'right': 'tick2On',

‎lib/matplotlib/tests/test_axes.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7539,15 +7539,19 @@ def test_tick_param_label_rotation():
75397539
ax.yaxis.set_tick_params(which='both', rotation=90)
75407540
for text in ax.get_xticklabels(which='both'):
75417541
assert text.get_rotation() == 75
7542+
assert text.get_rotation_mode() == 'default'
75427543
for text in ax.get_yticklabels(which='both'):
75437544
assert text.get_rotation() == 90
7545+
assert text.get_rotation_mode() == 'default'
75447546

7545-
ax2.tick_params(axis='x', labelrotation=53)
7546-
ax2.tick_params(axis='y', rotation=35)
7547+
ax2.tick_params(axis='x', labelrotation=53, labelrotation_mode='xtick')
7548+
ax2.tick_params(axis='y', rotation=35, rotation_mode='ytick')
75477549
for text in ax2.get_xticklabels(which='major'):
75487550
assert text.get_rotation() == 53
7551+
assert text.get_rotation_mode() == 'xtick'
75497552
for text in ax2.get_yticklabels(which='major'):
75507553
assert text.get_rotation() == 35
7554+
assert text.get_rotation_mode() == 'ytick'
75517555

75527556

75537557
@mpl.style.context('default')

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /