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

Appearance settings

Commit 28b4f51

Browse filesBrowse files
committed
Add appropriate error on color size mismatch in scatter
1 parent d7b8992 commit 28b4f51
Copy full SHA for 28b4f51

File tree

Expand file treeCollapse file tree

1 file changed

+6
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-5
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3974,14 +3974,15 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
39743974
else:
39753975
try:
39763976
c_array = np.asanyarray(c, dtype=float)
3977-
if c_array.size == x.size:
3978-
c = np.ma.ravel(c_array)
3979-
else:
3980-
# Wrong size; it must not be intended for mapping.
3981-
c_array = None
39823977
except ValueError:
39833978
# Failed to make a floating-point array; c must be color specs.
39843979
c_array = None
3980+
else:
3981+
if c_array.size == x.size:
3982+
c = np.ma.ravel(c_array)
3983+
elif c_array.size not in (3, 4):
3984+
# Wrong size. Not a rgb/rgba and not same size as x
3985+
raise ValueError("x and c must be the same size")
39853986

39863987
if c_array is None:
39873988
colors = c # must be acceptable as PathCollection facecolors

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.