Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add Axis.get_inverted and Axis.set_inverted. #13330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions doc/users/next_whats_new/2018-02-01-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Added `Axis.get_inverted` and `Axis.set_inverted`
`````````````````````````````````````````````````

The `Axis.get_inverted` and `Axis.set_inverted` methods query and set whether
the axis uses "inverted" orientation (i.e. increasing to the left for the
x-axis and to the bottom for the y-axis).

They perform tasks similar to `Axes.xaxis_inverted`, `Axes.yaxis_inverted`,
`Axes.invert_xaxis`, and `Axes.invert_yaxis`, with the specific difference that
`.set_inverted` makes it easier to set the invertedness of an axis regardless
of whether it had previously been inverted before.
10 changes: 4 additions & 6 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2998,7 +2998,7 @@ def invert_xaxis(self):
get_xlim, set_xlim
get_xbound, set_xbound
"""
self.set_xlim(self.get_xlim()[::-1], auto=None)
self.xaxis.set_inverted(not self.xaxis.get_inverted())

def xaxis_inverted(self):
"""
Expand All @@ -3012,8 +3012,7 @@ def xaxis_inverted(self):
get_xlim, set_xlim
get_xbound, set_xbound
"""
left, right = self.get_xlim()
return right < left
return self.xaxis.get_inverted()

def get_xbound(self):
"""
Expand Down Expand Up @@ -3404,7 +3403,7 @@ def invert_yaxis(self):
get_ylim, set_ylim
get_ybound, set_ybound
"""
self.set_ylim(self.get_ylim()[::-1], auto=None)
self.yaxis.set_inverted(not self.yaxis.get_inverted())

def yaxis_inverted(self):
"""
Expand All @@ -3418,8 +3417,7 @@ def yaxis_inverted(self):
get_ylim, set_ylim
get_ybound, set_ybound
"""
bottom, top = self.get_ylim()
return top < bottom
return self.yaxis.get_inverted()

def get_ybound(self):
"""
Expand Down
25 changes: 25 additions & 0 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,31 @@ def set_data_interval(self):
'''set the axis data limits'''
raise NotImplementedError('Derived must override')

def get_inverted(self):
"""
Return whether the axis is oriented in the "inverse" direction.

The "normal" direction is increasing to the right for the x-axis and to
the top for the y-axis; the "inverse" direction is increasing to the
left for the x-axis and to the bottom for the y-axis.
"""
low, high = self.get_view_interval()
return high < low

def set_inverted(self, inverted):
"""
Set whether the axis is oriented in the "inverse" direction.

The "normal" direction is increasing to the right for the x-axis and to
the top for the y-axis; the "inverse" direction is increasing to the
left for the x-axis and to the bottom for the y-axis.
"""
a, b = self.get_view_interval()
if inverted:
self.set_view_interval(max(a, b), min(a, b), ignore=True)
else:
self.set_view_interval(min(a, b), max(a, b), ignore=True)

def set_default_intervals(self):
'''set the default limits for the axis data and view interval if they
are not mutated'''
Expand Down