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 d7ee951

Browse filesBrowse 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 d7ee951
Copy full SHA for d7ee951

File tree

Expand file treeCollapse file tree

6 files changed

+72
-3
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+72
-3
lines changed

‎doc/api/axes_api.rst

Copy file name to clipboardExpand all lines: doc/api/axes_api.rst
+4Lines 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

Copy file name to clipboardExpand all lines: doc/api/toolkits/mplot3d/axes3d.rst
+6Lines 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
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Standard getters/setters for axis inversion state
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
Whether an axis is inverted can now be queried and set using the `.axes.Axes`
4+
getters `~.Axes.get_xinverted`/`~.Axes.get_yinverted` and setters
5+
`~.Axes.set_xinverted`/`~.Axes.set_yinverted`.
6+
7+
The previously existing methods (`.Axes.xaxis_inverted`, `.Axes.invert_xaxis`)
8+
are now discouraged (but not deprecated) due to their non-standard naming and
9+
behavior.

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+33-2Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from numbers import Real
77
from operator import attrgetter
88
import re
9+
import textwrap
910
import types
1011

1112
import numpy as np
@@ -3603,15 +3604,30 @@ def invert_xaxis(self):
36033604
"""
36043605
Invert the x-axis.
36053606
3607+
.. admonition:: Discouraged
3608+
3609+
The use of this method is discouraged.
3610+
Use `.Axes.set_xinverted` instead.
3611+
36063612
See Also
36073613
--------
3608-
xaxis_inverted
3614+
get_xinverted
36093615
get_xlim, set_xlim
36103616
get_xbound, set_xbound
36113617
"""
36123618
self.xaxis.set_inverted(not self.xaxis.get_inverted())
36133619

3620+
set_xinverted = _axis_method_wrapper("xaxis", "set_inverted")
3621+
get_xinverted = _axis_method_wrapper("xaxis", "get_inverted")
36143622
xaxis_inverted = _axis_method_wrapper("xaxis", "get_inverted")
3623+
if xaxis_inverted.__doc__:
3624+
xaxis_inverted.__doc__ += textwrap.dedent("""
3625+
3626+
.. admonition:: Discouraged
3627+
3628+
The use of this method is discouraged.
3629+
Use `.Axes.get_xinverted` instead.
3630+
""")
36153631

36163632
def get_xbound(self):
36173633
"""
@@ -3856,15 +3872,30 @@ def invert_yaxis(self):
38563872
"""
38573873
Invert the y-axis.
38583874
3875+
.. admonition:: Discouraged
3876+
3877+
The use of this method is discouraged.
3878+
Use `.Axes.set_yinverted` instead.
3879+
38593880
See Also
38603881
--------
3861-
yaxis_inverted
3882+
get_yinverted
38623883
get_ylim, set_ylim
38633884
get_ybound, set_ybound
38643885
"""
38653886
self.yaxis.set_inverted(not self.yaxis.get_inverted())
38663887

3888+
set_yinverted = _axis_method_wrapper("yaxis", "set_inverted")
3889+
get_yinverted = _axis_method_wrapper("yaxis", "get_inverted")
38673890
yaxis_inverted = _axis_method_wrapper("yaxis", "get_inverted")
3891+
if yaxis_inverted.__doc__:
3892+
yaxis_inverted.__doc__ += textwrap.dedent("""
3893+
3894+
.. admonition:: Discouraged
3895+
3896+
The use of this method is discouraged.
3897+
Use `.Axes.get_yinverted` instead.
3898+
""")
38683899

38693900
def get_ybound(self):
38703901
"""

‎lib/matplotlib/axes/_base.pyi

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.pyi
+4Lines 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

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/mplot3d/axes3d.py
+16-1Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1888,16 +1888,31 @@ def invert_zaxis(self):
18881888
"""
18891889
Invert the z-axis.
18901890
1891+
.. admonition:: Discouraged
1892+
1893+
The use of this method is discouraged.
1894+
Use `.Axes3D.set_zinverted` instead.
1895+
18911896
See Also
18921897
--------
1893-
zaxis_inverted
1898+
get_zinverted
18941899
get_zlim, set_zlim
18951900
get_zbound, set_zbound
18961901
"""
18971902
bottom, top = self.get_zlim()
18981903
self.set_zlim(top, bottom, auto=None)
18991904

1905+
set_zinverted = _axis_method_wrapper("zaxis", "set_inverted")
1906+
get_zinverted = _axis_method_wrapper("zaxis", "get_inverted")
19001907
zaxis_inverted = _axis_method_wrapper("zaxis", "get_inverted")
1908+
if zaxis_inverted.__doc__:
1909+
zaxis_inverted.__doc__ += textwrap.dedent("""
1910+
1911+
.. admonition:: Discouraged
1912+
1913+
The use of this method is discouraged.
1914+
Use `.Axes3D.get_zinverted` instead.
1915+
""")
19011916

19021917
def get_zbound(self):
19031918
"""

0 commit comments

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