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

Skip to content

Commit 7647550

Browse files
authored
Merge pull request matplotlib#18042 from QuLogic/scatter-size
scatter: Raise if unexpected type of `s` argument.
2 parents 0a83b9c + bda5766 commit 7647550

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4447,8 +4447,12 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
44474447
s = (20 if rcParams['_internal.classic_mode'] else
44484448
rcParams['lines.markersize'] ** 2.0)
44494449
s = np.ma.ravel(s)
4450-
if len(s) not in (1, x.size):
4451-
raise ValueError("s must be a scalar, or the same size as x and y")
4450+
if (len(s) not in (1, x.size) or
4451+
(not np.issubdtype(s.dtype, np.floating) and
4452+
not np.issubdtype(s.dtype, np.integer))):
4453+
raise ValueError(
4454+
"s must be a scalar, "
4455+
"or float array-like with the same size as x and y")
44524456

44534457
c, colors, edgecolors = \
44544458
self._parse_scatter_color_args(

lib/matplotlib/tests/test_axes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,10 +1909,12 @@ def test_scatter_unfilled(self):
19091909

19101910
def test_scatter_size_arg_size(self):
19111911
x = np.arange(4)
1912-
with pytest.raises(ValueError):
1912+
with pytest.raises(ValueError, match='same size as x and y'):
19131913
plt.scatter(x, x, x[1:])
1914-
with pytest.raises(ValueError):
1914+
with pytest.raises(ValueError, match='same size as x and y'):
19151915
plt.scatter(x[1:], x[1:], x)
1916+
with pytest.raises(ValueError, match='float array-like'):
1917+
plt.scatter(x, x, 'foo')
19161918

19171919
@check_figures_equal(extensions=["png"])
19181920
def test_scatter_invalid_color(self, fig_test, fig_ref):

0 commit comments

Comments
 (0)