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 1f1b8b8

Browse filesBrowse files
committed
Merge pull request #6267 from efiring/scatter-color
MNT: trap inappropriate use of color kwarg in scatter; closes #6266
1 parent 56dd604 commit 1f1b8b8
Copy full SHA for 1f1b8b8

File tree

Expand file treeCollapse file tree

2 files changed

+16
-8
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-8
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+9-8Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3812,19 +3812,20 @@ def scatter(self, x, y, s=20, c=None, marker='o', cmap=None, norm=None,
38123812
# Process **kwargs to handle aliases, conflicts with explicit kwargs:
38133813

38143814
facecolors = None
3815-
ec = kwargs.pop('edgecolor', None)
3816-
if ec is not None:
3817-
edgecolors = ec
3818-
fc = kwargs.pop('facecolor', None)
3819-
if fc is not None:
3820-
facecolors = fc
3815+
edgecolors = kwargs.pop('edgecolor', edgecolors)
38213816
fc = kwargs.pop('facecolors', None)
3817+
fc = kwargs.pop('facecolor', fc)
38223818
if fc is not None:
38233819
facecolors = fc
3824-
# 'color' should be deprecated in scatter, or clearly defined;
3825-
# since it isn't, I am giving it low priority.
38263820
co = kwargs.pop('color', None)
38273821
if co is not None:
3822+
try:
3823+
mcolors.colorConverter.to_rgba_array(co)
3824+
except ValueError:
3825+
raise ValueError("'color' kwarg must be an mpl color"
3826+
" spec or sequence of color specs.\n"
3827+
"For a sequence of values to be"
3828+
" color-mapped, use the 'c' kwarg instead.")
38283829
if edgecolors is None:
38293830
edgecolors = co
38303831
if facecolors is None:

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,13 @@ def test_scatter_2D():
12801280
fig, ax = plt.subplots()
12811281
ax.scatter(x, y, c=z, s=200, edgecolors='face')
12821282

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

12841291
@cleanup
12851292
def test_as_mpl_axes_api():

0 commit comments

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