Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2fc3ed6

Browse files
committed
Improve error messages for mismatched s arg to scatter().
- Display array sizes in case of size mismatch.- Display a clearer, distinct error message when `s` is not real.
1 parentfdf8995 commit2fc3ed6

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

‎lib/matplotlib/axes/_axes.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5309,12 +5309,12 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
53095309
s= (20ifmpl.rcParams['_internal.classic_mode']else
53105310
mpl.rcParams['lines.markersize']**2.0)
53115311
s=np.ma.ravel(s)
5312-
if(len(s)notin (1,x.size)or
5313-
(notnp.issubdtype(s.dtype,np.floating)and
5314-
notnp.issubdtype(s.dtype,np.integer))):
5315-
raiseValueError(
5316-
"s must bea scalar, "
5317-
"or float array-like with the same size asx and y")
5312+
ifnot(np.issubdtype(s.dtype,np.floating)
5313+
ornp.issubdtype(s.dtype,np.integer)):
5314+
raiseValueError(f"s must be float, but has type{s.dtype}")
5315+
iflen(s)notin (1,x.size):
5316+
raiseValueError(f"s (size{len(s)}) cannot bebroadcast "
5317+
f"to matchx and y (size{len(x)})")
53185318

53195319
# get the original edgecolor the user passed before we normalize
53205320
orig_edgecolor=edgecolors

‎lib/matplotlib/tests/test_axes.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2958,11 +2958,11 @@ def test_scatter_unfillable(self):
29582958

29592959
deftest_scatter_size_arg_size(self):
29602960
x=np.arange(4)
2961-
withpytest.raises(ValueError,match='same size as x and y'):
2961+
withpytest.raises(ValueError,match='cannot be broadcast to match x and y'):
29622962
plt.scatter(x,x,x[1:])
2963-
withpytest.raises(ValueError,match='same size as x and y'):
2963+
withpytest.raises(ValueError,match='cannot be broadcast to match x and y'):
29642964
plt.scatter(x[1:],x[1:],x)
2965-
withpytest.raises(ValueError,match='float array-like'):
2965+
withpytest.raises(ValueError,match='must be float'):
29662966
plt.scatter(x,x,'foo')
29672967

29682968
deftest_scatter_edgecolor_RGB(self):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp