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

Skip to content

Fix inconsistency between set_xlim and set_view_interval #6890

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

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix inconsistency between set_xlim and set_view_interval
Fix bug:
`Axes.xaxis.set_view_interval` , `Axes.xaxis.set_view_interval` do not
update twin axis as `set_xlim` do.

Add function:
`Axes._set_viewLim_intervalx`, `Axes._set_viewLim_intervaly`
  • Loading branch information
syrte committed Aug 3, 2016
commit 0bb718217a16d319b6639b4dde9830abeb108bc8
29 changes: 25 additions & 4 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2853,13 +2853,25 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
('Attempting to set identical left==right results\n'
'in singular transformations; automatically expanding.\n'
'left=%s, right=%s') % (left, right))

left, right = mtransforms.nonsingular(left, right, increasing=False)
left, right = self.xaxis.limit_range_for_scale(left, right)

self.viewLim.intervalx = (left, right)
if auto is not None:
self._autoscaleXon = bool(auto)

self._set_viewLim_intervalx(left, right, emit=emit)
return left, right

def _set_viewLim_intervalx(self, left, right, emit=True):
"""
Set the data limits for the xaxis
This should be the only method who can change viewLim.intervalx directly.

*emit*: [ *True* | *False* ]
Notify observers of limit change
"""
self.viewLim.intervalx = (left, right)
if emit:
self.callbacks.process('xlim_changed', self)
# Call all of the other x-axes that are shared with this one
Expand All @@ -2871,7 +2883,6 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
other.figure.canvas is not None):
other.figure.canvas.draw_idle()
self.stale = True
return left, right

def get_xscale(self):
return self.xaxis.get_scale()
Expand Down Expand Up @@ -3115,10 +3126,21 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw):
bottom, top = mtransforms.nonsingular(bottom, top, increasing=False)
bottom, top = self.yaxis.limit_range_for_scale(bottom, top)

self.viewLim.intervaly = (bottom, top)
if auto is not None:
self._autoscaleYon = bool(auto)

self._set_viewLim_intervaly(bottom, top, emit=emit)
return bottom, top

def _set_viewLim_intervaly(self, bottom, top, emit=True):
"""
Set the data limits for the yaxis
This should be the only method who can change viewLim.intervaly directly.

*emit*: [ *True* | *False* ]
Notify observers of limit change
"""
self.viewLim.intervaly = (bottom, top)
if emit:
self.callbacks.process('ylim_changed', self)
# Call all of the other y-axes that are shared with this one
Expand All @@ -3130,7 +3152,6 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw):
other.figure.canvas is not None):
other.figure.canvas.draw_idle()
self.stale = True
return bottom, top

def get_yscale(self):
return self.yaxis.get_scale()
Expand Down
23 changes: 12 additions & 11 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1960,15 +1960,16 @@ def set_view_interval(self, vmin, vmax, ignore=False):

"""
if ignore:
self.axes.viewLim.intervalx = vmin, vmax
left, right = vmin, vmax
else:
Vmin, Vmax = self.get_view_interval()
if Vmin < Vmax:
self.axes.viewLim.intervalx = (min(vmin, vmax, Vmin),
max(vmin, vmax, Vmax))
left, right = (min(vmin, vmax, Vmin),
max(vmin, vmax, Vmax))
else:
self.axes.viewLim.intervalx = (max(vmin, vmax, Vmin),
min(vmin, vmax, Vmax))
left, right = (max(vmin, vmax, Vmin),
min(vmin, vmax, Vmax))
self.axes._set_viewLim_intervalx(left, right)

def get_minpos(self):
return self.axes.dataLim.minposx
Expand Down Expand Up @@ -2299,16 +2300,16 @@ def set_view_interval(self, vmin, vmax, ignore=False):

"""
if ignore:
self.axes.viewLim.intervaly = vmin, vmax
bottom, top = vmin, vmax
else:
Vmin, Vmax = self.get_view_interval()
if Vmin < Vmax:
self.axes.viewLim.intervaly = (min(vmin, vmax, Vmin),
max(vmin, vmax, Vmax))
bottom, top = (min(vmin, vmax, Vmin),
max(vmin, vmax, Vmax))
else:
self.axes.viewLim.intervaly = (max(vmin, vmax, Vmin),
min(vmin, vmax, Vmax))
self.stale = True
bottom, top = (max(vmin, vmax, Vmin),
min(vmin, vmax, Vmax))
self.axes._set_viewLim_intervaly(bottom, top)

def get_minpos(self):
return self.axes.dataLim.minposy
Expand Down