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

Appearance settings

Commit 9af426b

Browse filesBrowse files
authored
[Bug Fix] Fix reverse mapping for _translate_tick_params (#29249)
1 parent 671177c commit 9af426b
Copy full SHA for 9af426b

File tree

Expand file treeCollapse file tree

2 files changed

+20
-6
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+20
-6
lines changed

‎lib/matplotlib/axis.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axis.py
+11-6Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,8 +1053,8 @@ def get_tick_params(self, which='major'):
10531053
)
10541054
return self._translate_tick_params(self._minor_tick_kw, reverse=True)
10551055

1056-
@staticmethod
1057-
def _translate_tick_params(kw, reverse=False):
1056+
@classmethod
1057+
def _translate_tick_params(cls, kw, reverse=False):
10581058
"""
10591059
Translate the kwargs supported by `.Axis.set_tick_params` to kwargs
10601060
supported by `.Tick._apply_params`.
@@ -1096,10 +1096,15 @@ def _translate_tick_params(kw, reverse=False):
10961096
'labeltop': 'label2On',
10971097
}
10981098
if reverse:
1099-
kwtrans = {
1100-
oldkey: kw_.pop(newkey)
1101-
for oldkey, newkey in keymap.items() if newkey in kw_
1102-
}
1099+
kwtrans = {}
1100+
is_x_axis = cls.axis_name == 'x'
1101+
y_axis_keys = ['left', 'right', 'labelleft', 'labelright']
1102+
for oldkey, newkey in keymap.items():
1103+
if newkey in kw_:
1104+
if is_x_axis and oldkey in y_axis_keys:
1105+
continue
1106+
else:
1107+
kwtrans[oldkey] = kw_.pop(newkey)
11031108
else:
11041109
kwtrans = {
11051110
newkey: kw_.pop(oldkey)

‎lib/matplotlib/tests/test_axis.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axis.py
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,12 @@ def test_axis_not_in_layout():
2929
# Positions should not be affected by overlapping 100 label
3030
assert ax1_left.get_position().bounds == ax2_left.get_position().bounds
3131
assert ax1_right.get_position().bounds == ax2_right.get_position().bounds
32+
33+
34+
def test_translate_tick_params_reverse():
35+
fig, ax = plt.subplots()
36+
kw = {'label1On': 'a', 'label2On': 'b', 'tick1On': 'c', 'tick2On': 'd'}
37+
assert (ax.xaxis._translate_tick_params(kw, reverse=True) ==
38+
{'labelbottom': 'a', 'labeltop': 'b', 'bottom': 'c', 'top': 'd'})
39+
assert (ax.yaxis._translate_tick_params(kw, reverse=True) ==
40+
{'labelleft': 'a', 'labelright': 'b', 'left': 'c', 'right': 'd'})

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.