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

Skip to content

Commit 46ac59a

Browse files
authored
Merge pull request #17718 from meeseeksmachine/auto-backport-of-pr-17715-on-v3.3.x
Backport PR #17715 on branch v3.3.x (Clarify gridspec error message for non-integer inputs.)
2 parents aa13340 + 427143d commit 46ac59a

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/matplotlib/gridspec.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ def __init__(self, nrows, ncols, height_ratios=None, width_ratios=None):
4545
If not given, all rows will have the same height.
4646
"""
4747
if not isinstance(nrows, Integral) or nrows <= 0:
48-
raise ValueError(f"Number of rows must be > 0, not {nrows}")
48+
raise ValueError(
49+
f"Number of rows must be a positive integer, not {nrows}")
4950
if not isinstance(ncols, Integral) or ncols <= 0:
50-
raise ValueError(f"Number of columns must be > 0, not {ncols}")
51+
raise ValueError(
52+
f"Number of columns must be a positive integer, not {ncols}")
5153
self._nrows, self._ncols = nrows, ncols
5254
self.set_height_ratios(height_ratios)
5355
self.set_width_ratios(width_ratios)

lib/matplotlib/tests/test_figure.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,11 @@ def test_gca():
182182

183183
def test_add_subplot_invalid():
184184
fig = plt.figure()
185-
with pytest.raises(ValueError, match='Number of columns must be > 0'):
185+
with pytest.raises(ValueError,
186+
match='Number of columns must be a positive integer'):
186187
fig.add_subplot(2, 0, 1)
187-
with pytest.raises(ValueError, match='Number of rows must be > 0'):
188+
with pytest.raises(ValueError,
189+
match='Number of rows must be a positive integer'):
188190
fig.add_subplot(0, 2, 1)
189191
with pytest.raises(ValueError, match='num must be 1 <= num <= 4'):
190192
fig.add_subplot(2, 2, 0)

0 commit comments

Comments
 (0)