File tree 3 files changed +40
-6
lines changed
3 files changed +40
-6
lines changed Original file line number Diff line number Diff line change
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.
Original file line number Diff line number Diff line change @@ -2998,7 +2998,7 @@ def invert_xaxis(self):
2998
2998
get_xlim, set_xlim
2999
2999
get_xbound, set_xbound
3000
3000
"""
3001
- self .set_xlim ( self .get_xlim ()[:: - 1 ], auto = None )
3001
+ self .xaxis . set_inverted ( not self .xaxis . get_inverted () )
3002
3002
3003
3003
def xaxis_inverted (self ):
3004
3004
"""
@@ -3012,8 +3012,7 @@ def xaxis_inverted(self):
3012
3012
get_xlim, set_xlim
3013
3013
get_xbound, set_xbound
3014
3014
"""
3015
- left , right = self .get_xlim ()
3016
- return right < left
3015
+ return self .xaxis .get_inverted ()
3017
3016
3018
3017
def get_xbound (self ):
3019
3018
"""
@@ -3404,7 +3403,7 @@ def invert_yaxis(self):
3404
3403
get_ylim, set_ylim
3405
3404
get_ybound, set_ybound
3406
3405
"""
3407
- self .set_ylim ( self .get_ylim ()[:: - 1 ], auto = None )
3406
+ self .yaxis . set_inverted ( not self .yaxis . get_inverted () )
3408
3407
3409
3408
def yaxis_inverted (self ):
3410
3409
"""
@@ -3418,8 +3417,7 @@ def yaxis_inverted(self):
3418
3417
get_ylim, set_ylim
3419
3418
get_ybound, set_ybound
3420
3419
"""
3421
- bottom , top = self .get_ylim ()
3422
- return top < bottom
3420
+ return self .yaxis .get_inverted ()
3423
3421
3424
3422
def get_ybound (self ):
3425
3423
"""
Original file line number Diff line number Diff line change @@ -909,6 +909,31 @@ def set_data_interval(self):
909
909
'''set the axis data limits'''
910
910
raise NotImplementedError ('Derived must override' )
911
911
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 ))
934
+ else :
935
+ self .set_view_interval (min (a , b ), max (a , b ))
936
+
912
937
def set_default_intervals (self ):
913
938
'''set the default limits for the axis data and view interval if they
914
939
are not mutated'''
You can’t perform that action at this time.
0 commit comments