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

Skip to content

Commit 28b4f51

Browse files
committed
Add appropriate error on color size mismatch in scatter
1 parent d7b8992 commit 28b4f51

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/matplotlib/axes/_axes.py

Lines 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)