Skip to content

Commit f71ddff

Browse files
committed
BUG: fix corner case in scatter color handling; closes #6362
1 parent 1156e23 commit f71ddff

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

lib/matplotlib/axes/_axes.py

+19-9
Original file line numberDiff line numberDiff line change
@@ -3835,11 +3835,18 @@ def scatter(self, x, y, s=20, c=None, marker='o', cmap=None, norm=None,
38353835
edgecolors = co
38363836
if facecolors is None:
38373837
facecolors = co
3838+
if c is not None:
3839+
raise ValueError("Supply a 'c' kwarg or a 'color' kwarg"
3840+
" but not both; they differ but"
3841+
" their functionalities overlap.")
38383842
if c is None:
38393843
if facecolors is not None:
38403844
c = facecolors
38413845
else:
38423846
c = 'b' # The original default
3847+
c_none = True
3848+
else:
3849+
c_none = False
38433850

38443851
self._process_unit_info(xdata=x, ydata=y, kwargs=kwargs)
38453852
x = self.convert_xunits(x)
@@ -3858,16 +3865,19 @@ def scatter(self, x, y, s=20, c=None, marker='o', cmap=None, norm=None,
38583865
# c is an array for mapping. The potential ambiguity
38593866
# with a sequence of 3 or 4 numbers is resolved in
38603867
# favor of mapping, not rgb or rgba.
3861-
try:
3862-
c_array = np.asanyarray(c, dtype=float)
3863-
if c_array.size == x.size:
3864-
c = np.ma.ravel(c_array)
3865-
else:
3866-
# Wrong size; it must not be intended for mapping.
3867-
c_array = None
3868-
except ValueError:
3869-
# Failed to make a floating-point array; c must be color specs.
3868+
if c_none or co is not None:
38703869
c_array = None
3870+
else:
3871+
try:
3872+
c_array = np.asanyarray(c, dtype=float)
3873+
if c_array.size == x.size:
3874+
c = np.ma.ravel(c_array)
3875+
else:
3876+
# Wrong size; it must not be intended for mapping.
3877+
c_array = None
3878+
except ValueError:
3879+
# Failed to make a floating-point array; c must be color specs.
3880+
c_array = None
38713881

38723882
if c_array is None:
38733883
colors = c # must be acceptable as PathCollection facecolors

0 commit comments

Comments
 (0)