From fe47f20dba37d9a293d4008ed1a22186dd96573c Mon Sep 17 00:00:00 2001 From: root Date: Wed, 24 May 2023 19:18:51 -0300 Subject: [PATCH] Raise on scatter plural and singular aliases --- lib/matplotlib/axes/_axes.py | 12 ++++++++++++ lib/matplotlib/tests/test_axes.py | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 6a3889cd05f6..087c0488c28e 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -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, diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 49bdc98abcb4..1760d4046381 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -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)