Skip to content

Raise errors on invalid axis limits #8216

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 4 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
Prev Previous commit
removed \, and moved error check after convert unit
Passed pep8
  • Loading branch information
alixxxin committed Mar 9, 2017
commit 7643d354b5f9b5ed89d945ec901cde284b45e4d6
16 changes: 8 additions & 8 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2874,14 +2874,14 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):

self._process_unit_info(xdata=(left, right))

if ((np.isscalar(left)) and not (np.isfinite(left))) \
or ((np.isscalar(right)) and (not np.isfinite(right))):
raise ValueError('left/right should be finite values')

if left is not None:
left = self.convert_xunits(left)
if ((np.isscalar(left)) and not (np.isfinite(left))):
raise ValueError('left/right should be finite values')
if right is not None:
right = self.convert_xunits(right)
if ((np.isscalar(right)) and (not np.isfinite(right))):
raise ValueError('left/right should be finite values')

old_left, old_right = self.get_xlim()
if left is None:
Expand Down Expand Up @@ -3172,14 +3172,14 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw):
if top is None and iterable(bottom):
bottom, top = bottom

if ((np.isscalar(top)) and not (np.isfinite(top))) \
or ((np.isscalar(bottom)) and (not np.isfinite(bottom))):
raise ValueError('top/bottom should be finite values')

if bottom is not None:
bottom = self.convert_yunits(bottom)
if ((np.isscalar(bottom)) and not (np.isfinite(bottom))):
raise ValueError('top/bottom should be finite values')
if top is not None:
top = self.convert_yunits(top)
if ((np.isscalar(top)) and (not np.isfinite(top))):
raise ValueError('top/bottom should be finite values')

old_bottom, old_top = self.get_ylim()

Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,7 @@ def test_axes():
with pytest.raises(ValueError):
ax.set_ylim(bottom=np.inf)


@image_comparison(baseline_images=['canonical'])
def test_canonical():
fig, ax = plt.subplots()
Expand Down
24 changes: 12 additions & 12 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,15 +602,15 @@ def set_xlim3d(self, left=None, right=None, emit=True, auto=False, **kw):
if right is None and cbook.iterable(left):
left, right = left

if ((np.isscalar(left)) and not (np.isfinite(left))) \
or ((np.isscalar(right)) and (not np.isfinite(right))):
raise ValueError('left/right should be finite values')

self._process_unit_info(xdata=(left, right))
if left is not None:
left = self.convert_xunits(left)
if ((np.isscalar(left)) and not (np.isfinite(left))):
raise ValueError('left/right should be finite values')
if right is not None:
right = self.convert_xunits(right)
if ((np.isscalar(right)) and (not np.isfinite(right))):
raise ValueError('left/right should be finite values')

old_left, old_right = self.get_xlim()
if left is None:
Expand Down Expand Up @@ -660,15 +660,15 @@ def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False, **kw):
if top is None and cbook.iterable(bottom):
bottom, top = bottom

if ((np.isscalar(top)) and not (np.isfinite(top))) \
or ((np.isscalar(bottom)) and (not np.isfinite(bottom))):
raise ValueError('top/bottom should be finite values')

self._process_unit_info(ydata=(bottom, top))
if bottom is not None:
bottom = self.convert_yunits(bottom)
if ((np.isscalar(bottom)) and not (np.isfinite(bottom))):
raise ValueError('bottom should be finite values')
if top is not None:
top = self.convert_yunits(top)
if ((np.isscalar(top)) and (not np.isfinite(top))):
raise ValueError('top should be finite values')

old_bottom, old_top = self.get_ylim()
if bottom is None:
Expand Down Expand Up @@ -720,14 +720,14 @@ def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False, **kw):

self._process_unit_info(zdata=(bottom, top))

if ((np.isscalar(top)) and not (np.isfinite(top))) \
or ((np.isscalar(bottom)) and (not np.isfinite(bottom))):
raise ValueError('top/bottom should be finite values')

if bottom is not None:
bottom = self.convert_zunits(bottom)
if ((np.isscalar(bottom)) and not (np.isfinite(bottom))):
raise ValueError('bottom should be finite values')
if top is not None:
top = self.convert_zunits(top)
if ((np.isscalar(top)) and (not np.isfinite(top))):
raise ValueError('top should be finite values')

old_bottom, old_top = self.get_zlim()
if bottom is None:
Expand Down