Skip to content

MNT: trap inappropriate use of color kwarg in scatter; closes #6266 #6267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3824,19 +3824,20 @@ def scatter(self, x, y, s=None, c=None, marker='o', cmap=None, norm=None,
# Process **kwargs to handle aliases, conflicts with explicit kwargs:

facecolors = None
ec = kwargs.pop('edgecolor', None)
if ec is not None:
edgecolors = ec
fc = kwargs.pop('facecolor', None)
if fc is not None:
facecolors = fc
edgecolors = kwargs.pop('edgecolor', edgecolors)
fc = kwargs.pop('facecolors', None)
fc = kwargs.pop('facecolor', fc)
if fc is not None:
facecolors = fc
# 'color' should be deprecated in scatter, or clearly defined;
# since it isn't, I am giving it low priority.
co = kwargs.pop('color', None)
if co is not None:
try:
mcolors.colorConverter.to_rgba_array(co)
except ValueError:
raise ValueError("'color' kwarg must be an mpl color"
" spec or sequence of color specs.\n"
"For a sequence of values to be"
" color-mapped, use the 'c' kwarg instead.")
if edgecolors is None:
edgecolors = co
if facecolors is None:
Expand Down
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,13 @@ def test_scatter_2D():
fig, ax = plt.subplots()
ax.scatter(x, y, c=z, s=200, edgecolors='face')

@cleanup
def test_scatter_color():
# Try to catch cases where 'c' kwarg should have been used.
assert_raises(ValueError, plt.scatter, [1, 2], [1, 2],
color=[0.1, 0.2])
assert_raises(ValueError, plt.scatter, [1, 2, 3], [1, 2, 3],
color=[1, 2, 3])

@cleanup
def test_as_mpl_axes_api():
Expand Down