Skip to content

Commit fe47f20

Browse files
rootroot
root
authored and
root
committed
Raise on scatter plural and singular aliases
1 parent a844eca commit fe47f20

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4552,6 +4552,18 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
45524552
size matches the size of *x* and *y*.
45534553
45544554
"""
4555+
# add edgecolors and linewidths to kwargs so they
4556+
# can be processed by normailze_kwargs
4557+
if edgecolors is not None:
4558+
kwargs.update({'edgecolors': edgecolors})
4559+
if linewidths is not None:
4560+
kwargs.update({'linewidths': linewidths})
4561+
4562+
kwargs = cbook.normalize_kwargs(kwargs, mcoll.Collection)
4563+
# re direct linewidth and edgecolor so it can be
4564+
# further processed by the rest of the function
4565+
linewidths = kwargs.pop('linewidth', None)
4566+
edgecolors = kwargs.pop('edgecolor', None)
45554567
# Process **kwargs to handle aliases, conflicts with explicit kwargs:
45564568
x, y = self._process_unit_info([("x", x), ("y", y)], kwargs)
45574569
# np.ma.ravel yields an ndarray, not a masked array,

lib/matplotlib/tests/test_axes.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,6 +2704,27 @@ def test_scatter_linewidths(self):
27042704
assert_array_equal(pc.get_linewidths(),
27052705
[*range(1, 5), mpl.rcParams['lines.linewidth']])
27062706

2707+
def test_scatter_singular_plural_arguments(self):
2708+
2709+
with pytest.raises(TypeError,
2710+
match="Got both 'linewidth' and 'linewidths',\
2711+
which are aliases of one another"):
2712+
plt.scatter([1, 2, 3], [1, 2, 3], linewidths=[0.5, 0.4, 0.3], linewidth=0.2)
2713+
2714+
with pytest.raises(TypeError,
2715+
match="Got both 'edgecolor' and 'edgecolors',\
2716+
which are aliases of one another"):
2717+
plt.scatter([1, 2, 3], [1, 2, 3],
2718+
edgecolors=["#ffffff", "#000000", "#f0f0f0"],
2719+
edgecolor="#ffffff")
2720+
2721+
with pytest.raises(TypeError,
2722+
match="Got both 'facecolors' and 'facecolor',\
2723+
which are aliases of one another"):
2724+
plt.scatter([1, 2, 3], [1, 2, 3],
2725+
facecolors=["#ffffff", "#000000", "#f0f0f0"],
2726+
facecolor="#ffffff")
2727+
27072728

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

0 commit comments

Comments
 (0)