8000 Raise on plural scatter by Luna-v0 · Pull Request #25794 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Raise on plural scatter #25794

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
May 26, 2023
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
12 changes: 12 additions & 0 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4552,6 +4552,18 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
size matches the size of *x* and *y*.

"""
# add edgecolors and linewidths to kwargs so they
# can be processed by normailze_kwargs
if edgecolors is not None:
kwargs.update({'edgecolors': edgecolors})
if linewidths is not None:
kwargs.update({'linewidths': linewidths})

kwargs = cbook.normalize_kwargs(kwargs, mcoll.Collection)
# re direct linewidth and edgecolor so it can be
# further processed by the rest of the function
linewidths = kwargs.pop('linewidth', None)
edgecolors = kwargs.pop('edgecolor', None)
# Process **kwargs to handle aliases, conflicts with explicit kwargs:
x, y = self._process_unit_info([("x", x), ("y", y)], kwargs)
# np.ma.ravel yields an ndarray, not a masked array,
Expand Down
21 changes: 21 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2704,6 +2704,27 @@ def test_scatter_linewidths(self):
assert_array_equal(pc.get_linewidths(),
[*range(1, 5), mpl.rcParams['lines.linewidth']])

def test_scatter_singular_plural_arguments(self):

with pytest.raises(TypeError,
match="Got both 'linewidth' and 'linewidths',\
which are aliases of one another"):
plt.scatter([1, 2, 3], [1, 2, 3], linewidths=[0.5, 0.4, 0.3], linewidth=0.2)

with pytest.raises(TypeError,
match="Got both 'edgecolor' and 'edgecolors',\
which are aliases of one another"):
plt.scatter([1, 2, 3], [1, 2, 3],
edgecolors=["#ffffff", "#000000", "#f0f0f0"],
edgecolor="#ffffff")

with pytest.raises(TypeError,
match="Got both 'facecolors' and 'facecolor',\
which are aliases of one another"):
plt.scatter([1, 2, 3], [1, 2, 3],
facecolors=["#ffffff", "#000000", "#f0f0f0"],
facecolor="#ffffff")


def _params(c=None, xsize=2, *, edgecolors=None, **kwargs):
return (c, edgecolors, kwargs if kwargs is not None else {}, xsize)
Expand Down
0