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

Skip to content

Commit 0b6aa7b

Browse files
committed
Merge pull request #6267 from efiring/scatter-color
MNT: trap inappropriate use of color kwarg in scatter; closes #6266
2 parents 3b2ab9d + d28c02e commit 0b6aa7b

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3824,19 +3824,20 @@ def scatter(self, x, y, s=None, c=None, marker='o', cmap=None, norm=None,
38243824
# Process **kwargs to handle aliases, conflicts with explicit kwargs:
38253825

38263826
facecolors = None
3827-
ec = kwargs.pop('edgecolor', None)
3828-
if ec is not None:
3829-
edgecolors = ec
3830-
fc = kwargs.pop('facecolor', None)
3831-
if fc is not None:
3832-
facecolors = fc
3827+
edgecolors = kwargs.pop('edgecolor', edgecolors)
38333828
fc = kwargs.pop('facecolors', None)
3829+
fc = kwargs.pop('facecolor', fc)
38343830
if fc is not None:
38353831
facecolors = fc
3836-
# 'color' should be deprecated in scatter, or clearly defined;
3837-
# since it isn't, I am giving it low priority.
38383832
co = kwargs.pop('color', None)
38393833
if co is not None:
3834+
try:
3835+
mcolors.colorConverter.to_rgba_array(co)
3836+
except ValueError:
3837+
raise ValueError("'color' kwarg must be an mpl color"
3838+
" spec or sequence of color specs.\n"
3839+
"For a sequence of values to be"
3840+
" color-mapped, use the 'c' kwarg instead.")
38403841
if edgecolors is None:
38413842
edgecolors = co
38423843
if facecolors is None:

lib/matplotlib/tests/test_axes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,13 @@ def test_scatter_2D():
12831283
fig, ax = plt.subplots()
12841284
ax.scatter(x, y, c=z, s=200, edgecolors='face')
12851285

1286+
@cleanup
1287+
def test_scatter_color():
1288+
# Try to catch cases where 'c' kwarg should have been used.
1289+
assert_raises(ValueError, plt.scatter, [1, 2], [1, 2],
1290+
color=[0.1, 0.2])
1291+
assert_raises(ValueError, plt.scatter, [1, 2, 3], [1, 2, 3],
1292+
color=[1, 2, 3])
12861293

12871294
@cleanup
12881295
def test_as_mpl_axes_api():

0 commit comments

Comments
 (0)