8000 Add "standard" Axes wrapper getters/setters for Axis invertedness. · matplotlib/matplotlib@3c6eca7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3c6eca7

Browse files
committed
Add "standard" Axes wrapper getters/setters for Axis invertedness.
Currently, toggling an axis invertedness requires either using the Axes method `ax.invert_xaxis()` (whose effect depends on whether it has already been called before) or going through the axis method `ax.xaxis.set_inverted()`; likewise, querying invertedness state requires either using the `ax.xaxis_inverted()` method, which has slightly nonstandard naming, or going through the axis method `ax.xaxis.get_inverted()`. For practicality, provide getters and setters with standard names: `ax.get_xinverted()`/`ax.set_xinverted()` (and likewise for y/z). In particular, the "standard" setter can be used with the multi-setter Artist.set(), or directly when creating the axes (`add_subplot(xinverted=True)`).
1 parent 773096e commit 3c6eca7

File tree

6 files changed

+27
-6
lines changed

6 files changed

+27
-6
lines changed

doc/api/axes_api.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,12 @@ Axis limits and direction
285285
:template: autosummary.rst
286286
:nosignatures:
287287

288+
Axes.set_xinverted
289+
Axes.get_xinverted
288290
Axes.invert_xaxis
289291
Axes.xaxis_inverted
292+
Axes.set_yinverted
293+
Axes.get_yinverted
290294
Axes.invert_yaxis
291295
Axes.yaxis_inverted
292296

doc/api/toolkits/mplot3d/axes3d.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,16 @@ Axis limits and direction
9999
get_zlim
100100
set_zlim
101101
get_w_lims
102+
get_xinverted
103+
set_xinverted
102104
invert_xaxis
103105
xaxis_inverted
106+
get_yinverted
107+
set_yinverted
104108
invert_yaxis
105109
yaxis_inverted
110+
get_zinverted
111+
set_zinverted
106112
invert_zaxis
107113
zaxis_inverted
108114
get_xbound
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Standard getters/setters for axis inversion state
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
Whether an axis is inverted can now be queried and set using the `.Axes` getters
4+
`.get_xinverted`/`.get_yinverted` and setters `.set_xinverted`/`.set_yinverted`.

lib/matplotlib/axes/_base.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3605,13 +3605,14 @@ def invert_xaxis(self):
36053605
36063606
See Also
36073607
--------
3608-
xaxis_inverted
3608+
get_xinverted
36093609
get_xlim, set_xlim
36103610
get_xbound, set_xbound
36113611
"""
36123612
self.xaxis.set_inverted(not self.xaxis.get_inverted())
36133613

3614-
xaxis_inverted = _axis_method_wrapper("xaxis", "get_inverted")
3614+
set_xinverted = _axis_method_wrapper("xaxis", "set_inverted")
3615+
get_xinverted = xaxis_inverted = _axis_method_wrapper("xaxis", "get_inverted")
36153616

36163617
def get_xbound(self):
36173618
"""
@@ -3858,13 +3859,14 @@ def invert_yaxis(self):
38583859
38593860
See Also
38603861
--------
3861-
yaxis_inverted
3862+
get_yinverted
38623863
get_ylim, set_ylim
38633864
get_ybound, set_ybound
38643865
"""
38653866
self.yaxis.set_inverted(not self.yaxis.get_inverted())
38663867

3867-
yaxis_inverted = _axis_method_wrapper("yaxis", "get_inverted")
3868+
set_yinverted = _axis_method_wrapper("yaxis", "set_inverted")
3869+
get_yinverted = yaxis_inverted = _axis_method_wrapper("yaxis", "get_inverted")
38683870

38693871
def get_ybound(self):
38703872
"""

lib/matplotlib/axes/_base.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,9 @@ class _AxesBase(martist.Artist):
405405
def get_autoscaley_on(self) -> bool: ...
406406
def set_autoscalex_on(self, b: bool) -> None: ...
407407
def set_autoscaley_on(self, b: bool) -> None: ...
408+
def get_xinverted(self) -> bool: ...
408409
def xaxis_inverted(self) -> bool: ...
410+
def set_xinverted(self, inverted: bool) -> None: ...
409411
def get_xscale(self) -> str: ...
410412
def set_xscale(self, value: str | ScaleBase, **kwargs) -> None: ...
411413
def get_xticks(self, *, minor: bool = ...) -> np.ndarray: ...
@@ -430,7 +432,9 @@ class _AxesBase(martist.Artist):
430432
fontdict: dict[str, Any] | None = ...,
431433
**kwargs
432434
) -> list[Text]: ...
435+
def get_yinverted(self) -> bool: ...
433436
def yaxis_inverted(self) -> bool: ...
437+
def set_yinverted(self, inverted: bool) -> None: ...
434438
def get_yscale(self) -> str: ...
435439
def set_yscale(self, value: str | ScaleBase, **kwargs) -> None: ...
436440
def get_yticks(self, *, minor: bool = ...) -> np.ndarray: ...

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,14 +1890,15 @@ def invert_zaxis(self):
18901890
18911891
See Also
18921892
--------
1893-
zaxis_inverted
1893+
get_zinverted
18941894
get_zlim, set_zlim
18951895
get_zbound, set_zbound
18961896
"""
18971897
bottom, top = self.get_zlim()
18981898
self.set_zlim(top, bottom, auto=None)
18991899

1900-
zaxis_inverted = _axis_method_wrapper("zaxis", "get_inverted")
1900+
set_zinverted = _axis_method_wrapper("zaxis", "set_inverted")
1901+
get_zinverted = zaxis_inverted = _axis_method_wrapper("zaxis", "get_inverted")
19011902

19021903
def get_zbound(self):
19031904
"""

0 commit comments

Comments
 (0)
0