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

Skip to content

Fixed Issue #7460: Raised an error if argument to xlim is invalid #8022

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 2 commits into from
Apr 13, 2017
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
30 changes: 18 additions & 12 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,18 @@ def _determine_lims(self, xmin=None, xmax=None, *args, **kwargs):
xmax += 0.05
return (xmin, xmax)

def _validate_axis_limits(self, limit, convert):
"""
Raise ValueError if specified axis limits are infinite.

"""
if limit is not None:
converted_limits = convert(limit)
if (isinstance(limit, float) and
(not np.isreal(limit) or not np.isfinite(limit))):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh bother, I just noticed this should probably be checking the converted limits. Do you want to open a new PR for that, @nvedant07?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure , i have opened a new PR for this - #8474

raise ValueError("Axis limits cannot be NaN or Inf")
return converted_limits

def set_xlim3d(self, left=None, right=None, emit=True, auto=False, **kw):
"""
Set 3D x limits.
Expand All @@ -605,10 +617,8 @@ def set_xlim3d(self, left=None, right=None, emit=True, auto=False, **kw):
left, right = left

self._process_unit_info(xdata=(left, right))
if left is not None:
left = self.convert_xunits(left)
if right is not None:
right = self.convert_xunits(right)
left = self._validate_axis_limits(left, self.convert_xunits)
right = self._validate_axis_limits(right, self.convert_xunits)

old_left, old_right = self.get_xlim()
if left is None:
Expand Down Expand Up @@ -665,10 +675,8 @@ def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False, **kw):
top = self.convert_yunits(top)

old_bottom, old_top = self.get_ylim()
if bottom is None:
bottom = old_bottom
if top is None:
top = old_top
bottom = self._validate_axis_limits(bottom, self.convert_yunits)
top = self._validate_axis_limits(top, self.convert_yunits)

if top == bottom:
warnings.warn(('Attempting to set identical bottom==top results\n'
Expand Down Expand Up @@ -713,10 +721,8 @@ def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False, **kw):
bottom, top = bottom

self._process_unit_info(zdata=(bottom, top))
if bottom is not None:
bottom = self.convert_zunits(bottom)
if top is not None:
top = self.convert_zunits(top)
bottom = self._validate_axis_limits(bottom, self.convert_yunits)
top = self._validate_axis_limits(top, self.convert_yunits)

old_bottom, old_top = self.get_zlim()
if bottom is None:
Expand Down
17 changes: 17 additions & 0 deletions lib/mpl_toolkits/tests/test_mplot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,3 +547,20 @@ def test_axes3d_ortho():
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_proj_type('ortho')


@pytest.mark.parametrize('value', [np.inf, np.nan])
@pytest.mark.parametrize(('setter', 'side'), [
('set_xlim3d', 'left'),
('set_xlim3d', 'right'),
('set_ylim3d', 'bottom'),
('set_ylim3d', 'top'),
('set_zlim3d', 'bottom'),
('set_zlim3d', 'top'),
])
def test_invalid_axes_limits(setter, side, value):
limit = {side: value}
fig = plt.figure()
obj = fig.add_subplot(111, projection='3d')
with pytest.raises(ValueError):
getattr(obj, setter)(**limit)