Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug Fix] Fix reverse mapping for _translate_tick_params #29249

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 2 commits into from
Dec 8, 2024
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
17 changes: 11 additions & 6 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,8 @@ def get_tick_params(self, which='major'):
)
return self._translate_tick_params(self._minor_tick_kw, reverse=True)

@staticmethod
def _translate_tick_params(kw, reverse=False):
@classmethod
def _translate_tick_params(cls, kw, reverse=False):
"""
Translate the kwargs supported by `.Axis.set_tick_params` to kwargs
supported by `.Tick._apply_params`.
Expand Down Expand Up @@ -1096,10 +1096,15 @@ def _translate_tick_params(kw, reverse=False):
'labeltop': 'label2On',
}
if reverse:
kwtrans = {
oldkey: kw_.pop(newkey)
for oldkey, newkey in keymap.items() if newkey in kw_
}
kwtrans = {}
is_x_axis = cls.axis_name == 'x'
y_axis_keys = ['left', 'right', 'labelleft', 'labelright']
for oldkey, newkey in keymap.items():
if newkey in kw_:
if is_x_axis and oldkey in y_axis_keys:
continue
else:
kwtrans[oldkey] = kw_.pop(newkey)
else:
kwtrans = {
newkey: kw_.pop(oldkey)
Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,12 @@ def test_axis_not_in_layout():
# Positions should not be affected by overlapping 100 label
assert ax1_left.get_position().bounds == ax2_left.get_position().bounds
assert ax1_right.get_position().bounds == ax2_right.get_position().bounds


def test_translate_tick_params_reverse():
fig, ax = plt.subplots()
kw = {'label1On': 'a', 'label2On': 'b', 'tick1On': 'c', 'tick2On': 'd'}
assert (ax.xaxis._translate_tick_params(kw, reverse=True) ==
{'labelbottom': 'a', 'labeltop': 'b', 'bottom': 'c', 'top': 'd'})
assert (ax.yaxis._translate_tick_params(kw, reverse=True) ==
{'labelleft': 'a', 'labelright': 'b', 'left': 'c', 'right': 'd'})
Loading