diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index cc36b6871778..556883ad005a 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -4492,7 +4492,12 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, marker_obj.get_transform()) if not marker_obj.is_filled(): edgecolors = 'face' - linewidths = rcParams['lines.linewidth'] + if linewidths is None: + linewidths = rcParams['lines.linewidth'] + elif np.iterable(linewidths): + linewidths = [ + lw if lw is not None else rcParams['lines.linewidth'] + for lw in linewidths] offsets = np.ma.column_stack([x, y]) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index b8930ccdfba0..fba1811fa05f 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -1984,6 +1984,20 @@ def test_scatter_single_color_c(self, fig_test, fig_ref): ax_test.scatter(np.ones(3), range(3), c=rgb) ax_test.scatter(np.ones(4)*2, range(4), c=rgba) + def test_scatter_linewidths(self): + x = np.arange(5) + + fig, ax = plt.subplots() + for i in range(3): + pc = ax.scatter(x, np.full(5, i), c=f'C{i}', marker='x', s=100, + linewidths=i + 1) + assert pc.get_linewidths() == i + 1 + + pc = ax.scatter(x, np.full(5, 3), c='C3', marker='x', s=100, + linewidths=[*range(1, 5), None]) + assert_array_equal(pc.get_linewidths(), + [*range(1, 5), mpl.rcParams['lines.linewidth']]) + def _params(c=None, xsize=2, *, edgecolors=None, **kwargs): return (c, edgecolors, kwargs if kwargs is not None else {}, xsize)