Repository: matplotlib/matplotlib

Issue:
[Bug]: get_tick_params on xaxis shows wrong keywords
### Bug summary

`get_tick_params` on xaxis shows yaxis keywords

### Code for reproduction

```python
import matplotlib.pyplot as plt

fig, ax = plt.subplots()

print(ax.xaxis.get_tick_params())
```


### Actual outcome

{'left': True, 'right': False, 'labelleft': True, 'labelright': False, 'gridOn': False}

### Expected outcome

{'bottom': True, 'top': False, 'labelbottom': True, 'labeltop': False, 'gridOn': False}

### Additional information

The current implementation of `get_tick_params` tries to invert the [`keymap`](https://github.com/matplotlib/matplotlib/blob/eb02b108ea181930ab37717c75e07ba792e01f1d/lib/matplotlib/axis.py#L1071-L1084) dict which is impossible because this dict is a 1:n relationship (multiple keys with the same value).  
This went unnoticed because the [test_axis_get_tick_params](https://github.com/matplotlib/matplotlib/blob/379989e9529b9c98dc866a338b272beedf1f697a/lib/matplotlib/tests/test_axes.py#L6794) didn't actually test anything: the expected value is _calculated_ in the test using the very same algorithm as the function under test.

### Operating system

_No response_

### Matplotlib Version

3.8.2

### Matplotlib Backend

_No response_

### Python version

_No response_

### Jupyter version

_No response_

### Installation

None


Discussion:

Patch:
diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py
index f258fa904c34..41b23bec8428 100644
--- a/lib/matplotlib/axis.py
+++ b/lib/matplotlib/axis.py
@@ -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`.
@@ -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)


Test patch:
diff --git a/lib/matplotlib/tests/test_axis.py b/lib/matplotlib/tests/test_axis.py
index 33af30662a33..c1b09006607d 100644
--- a/lib/matplotlib/tests/test_axis.py
+++ b/lib/matplotlib/tests/test_axis.py
@@ -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'})