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

Skip to content

Commit e5cc8e1

Browse files
committed
Change invalid axis limit error to warning
1 parent 22387cc commit e5cc8e1

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2875,17 +2875,16 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw):
28752875
if right is not None:
28762876
right = self.convert_xunits(right)
28772877

2878-
if ((left is not None and not np.isfinite(left)) or
2879-
(right is not None and not np.isfinite(right))):
2880-
raise ValueError("xlim limits must be finite. "
2881-
"instead, found: (%s, %s)" % (left, right))
2882-
28832878
old_left, old_right = self.get_xlim()
28842879
if left is None:
28852880
left = old_left
28862881
if right is None:
28872882
right = old_right
28882883

2884+
if not (np.isfinite(left) and np.isfinite(right)):
2885+
warnings.warn('xlim limits must be finite.\n'
2886+
'instead, found: (%s, %s)' % (left, right))
2887+
28892888
if left == right:
28902889
warnings.warn(
28912890
('Attempting to set identical left==right results\n'
@@ -3159,18 +3158,17 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw):
31593158
if top is not None:
31603159
top = self.convert_yunits(top)
31613160

3162-
if ((top is not None and not np.isfinite(top)) or
3163-
(bottom is not None and not np.isfinite(bottom))):
3164-
raise ValueError("ylim limits must be finite. "
3165-
"instead, found: (%s, %s)" % (top, bottom))
3166-
31673161
old_bottom, old_top = self.get_ylim()
31683162

31693163
if bottom is None:
31703164
bottom = old_bottom
31713165
if top is None:
31723166
top = old_top
31733167

3168+
if not (np.isfinite(top) and np.isfinite(bottom)):
3169+
warnings.warn('ylim limits must be finite.\n'
3170+
'instead, found: (%s, %s)' % (top, bottom))
3171+
31743172
if bottom == top:
31753173
warnings.warn(
31763174
('Attempting to set identical bottom==top results\n'

lib/matplotlib/tests/test_axes.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4880,13 +4880,12 @@ def test_eventplot_legend():
48804880

48814881

48824882
@cleanup
4883-
def test_invalid_axis_limits():
4883+
def test_invalid_axis_warnings():
48844884
plt.plot([0, 1], [0, 1])
4885-
with pytest.raises(ValueError):
4885+
with warnings.catch_warnings(record=True) as w:
4886+
warnings.simplefilter("always")
48864887
plt.xlim(np.nan)
4887-
with pytest.raises(ValueError):
48884888
plt.xlim(np.inf)
4889-
with pytest.raises(ValueError):
48904889
plt.ylim(np.nan)
4891-
with pytest.raises(ValueError):
48924890
plt.ylim(np.inf)
4891+
assert len(w) == 4

0 commit comments

Comments
 (0)