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

Skip to content

Commit 4e22479

Browse files
author
Vedant Nanda
committed
moved _validate_axis_limits in base class
1 parent a6b53b0 commit 4e22479

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2810,6 +2810,19 @@ def get_xlim(self):
28102810
"""
28112811
return tuple(self.viewLim.intervalx)
28122812

2813+
def _validate_axis_limits(self, limit, convert):
2814+
"""
2815+
Raise ValueError if specified axis limits are infinite.
2816+
2817+
"""
2818+
if limit is not None:
2819+
converted_limit = convert(limit)
2820+
if (isinstance(converted_limit, float) and
2821+
(not np.isreal(converted_limit) or
2822+
not np.isfinite(converted_limit))):
2823+
raise ValueError("Axis limits cannot be NaN or Inf")
2824+
return converted_limit
2825+
28132826
def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
28142827
"""
28152828
Set the data limits for the x-axis
@@ -2876,15 +2889,8 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
28762889
left, right = left
28772890

28782891
self._process_unit_info(xdata=(left, right))
2879-
if left is not None:
2880-
left = self.convert_xunits(left)
2881-
if right is not None:
2882-
right = self.convert_xunits(right)
2883-
2884-
if ((left is not None and not np.isfinite(left)) or
2885-
(right is not None and not np.isfinite(right))):
2886-
raise ValueError("Specified x limits must be finite; "
2887-
"instead, found: (%s, %s)" % (left, right))
2892+
left = self._validate_axis_limits(left, self.convert_xunits)
2893+
right = self._validate_axis_limits(right, self.convert_xunits)
28882894

28892895
old_left, old_right = self.get_xlim()
28902896
if left is None:
@@ -3175,15 +3181,8 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw):
31753181
if top is None and iterable(bottom):
31763182
bottom, top = bottom
31773183

3178-
if bottom is not None:
3179-
bottom = self.convert_yunits(bottom)
3180-
if top is not None:
3181-
top = self.convert_yunits(top)
3182-
3183-
if ((top is not None and not np.isfinite(top)) or
3184-
(bottom is not None and not np.isfinite(bottom))):
3185-
raise ValueError("Specified y limits must be finite; "
3186-
"instead, found: (%s, %s)" % (bottom, top))
3184+
bottom = self._validate_axis_limits(bottom, self.convert_yunits)
3185+
top = self._validate_axis_limits(top, self.convert_yunits)
31873186

31883187
old_bottom, old_top = self.get_ylim()
31893188

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -587,17 +587,17 @@ def _determine_lims(self, xmin=None, xmax=None, *args, **kwargs):
587587
xmax += 0.05
588588
return (xmin, xmax)
589589

590-
def _validate_axis_limits(self, limit, convert):
591-
"""
592-
Raise ValueError if specified axis limits are infinite.
593-
594-
"""
595-
if limit is not None:
596-
converted_limit = convert(limit)
597-
if (isinstance(converted_limit, float) and
598-
(not np.isreal(converted_limit) or not np.isfinite(converted_limit))):
599-
raise ValueError("Axis limits cannot be NaN or Inf")
600-
return converted_limit
590+
# def _validate_axis_limits(self, limit, convert):
591+
# """
592+
# Raise ValueError if specified axis limits are infinite.
593+
594+
# """
595+
# if limit is not None:
596+
# converted_limit = convert(limit)
597+
# if (isinstance(converted_limit, float) and
598+
# (not np.isreal(converted_limit) or not np.isfinite(converted_limit))):
599+
# raise ValueError("Axis limits cannot be NaN or Inf")
600+
# return converted_limit
601601

602602
def set_xlim3d(self, left=None, right=None, emit=True, auto=False, **kw):
603603
"""

0 commit comments

Comments
 (0)