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 01aedbc

Browse filesBrowse files
committed
Add Axis.get_inverted and Axis.set_inverted.
See rationale in changelog note (basically, Axes.invert_xaxis is fine for interactive use, but a bit of a pain for library-work). Note that xaxis_inverted is now implemented in terms of get_inverted and invert_xaxis in terms of set_inverted, so the new methods are properly tested.
1 parent 623b789 commit 01aedbc
Copy full SHA for 01aedbc

File tree

Expand file treeCollapse file tree

3 files changed

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

3 files changed

+40
-6
lines changed
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Added `Axis.get_inverted` and `Axis.set_inverted`
2+
`````````````````````````````````````````````````
3+
4+
The `Axis.get_inverted` and `Axis.set_inverted` methods query and set whether
5+
the axis uses "inverted" orientation (i.e. increasing to the left for the
6+
x-axis and to the bottom for the y-axis).
7+
8+
They perform tasks similar to `Axes.xaxis_inverted`, `Axes.yaxis_inverted`,
9+
`Axes.invert_xaxis`, and `Axes.invert_yaxis`, with the specific difference that
10+
`.set_inverted` makes it easier to set the invertedness of an axis regardless
11+
of whether it had previously been inverted before.

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+4-6Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2998,7 +2998,7 @@ def invert_xaxis(self):
29982998
get_xlim, set_xlim
29992999
get_xbound, set_xbound
30003000
"""
3001-
self.set_xlim(self.get_xlim()[::-1], auto=None)
3001+
self.xaxis.set_inverted(not self.xaxis.get_inverted())
30023002

30033003
def xaxis_inverted(self):
30043004
"""
@@ -3012,8 +3012,7 @@ def xaxis_inverted(self):
30123012
get_xlim, set_xlim
30133013
get_xbound, set_xbound
30143014
"""
3015-
left, right = self.get_xlim()
3016-
return right < left
3015+
return self.xaxis.get_inverted()
30173016

30183017
def get_xbound(self):
30193018
"""
@@ -3404,7 +3403,7 @@ def invert_yaxis(self):
34043403
get_ylim, set_ylim
34053404
get_ybound, set_ybound
34063405
"""
3407-
self.set_ylim(self.get_ylim()[::-1], auto=None)
3406+
self.yaxis.set_inverted(not self.yaxis.get_inverted())
34083407

34093408
def yaxis_inverted(self):
34103409
"""
@@ -3418,8 +3417,7 @@ def yaxis_inverted(self):
34183417
get_ylim, set_ylim
34193418
get_ybound, set_ybound
34203419
"""
3421-
bottom, top = self.get_ylim()
3422-
return top < bottom
3420+
return self.yaxis.get_inverted()
34233421

34243422
def get_ybound(self):
34253423
"""

‎lib/matplotlib/axis.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axis.py
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,31 @@ def set_data_interval(self):
909909
'''set the axis data limits'''
910910
raise NotImplementedError('Derived must override')
911911

912+
def get_inverted(self):
913+
"""
914+
Return whether the axis is oriented in the "inverse" direction.
915+
916+
The "normal" direction is increasing to the right for the x-axis and to
917+
the top for the y-axis; the "inverse" direction is increasing to the
918+
left for the x-axis and to the bottom for the y-axis.
919+
"""
920+
low, high = self.get_view_interval()
921+
return high < low
922+
923+
def set_inverted(self, inverted):
924+
"""
925+
Set whether the axis is oriented in the "inverse" direction.
926+
927+
The "normal" direction is increasing to the right for the x-axis and to
928+
the top for the y-axis; the "inverse" direction is increasing to the
929+
left for the x-axis and to the bottom for the y-axis.
930+
"""
931+
a, b = self.get_view_interval()
932+
if inverted:
933+
self.set_view_interval(max(a, b), min(a, b), ignore=True)
934+
else:
935+
self.set_view_interval(min(a, b), max(a, b), ignore=True)
936+
912937
def set_default_intervals(self):
913938
'''set the default limits for the axis data and view interval if they
914939
are not mutated'''

0 commit comments

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