diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index b290ae324432..c28c79cd00e7 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -2779,8 +2779,9 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0, # New behaviour in 3.1 is to use a LineCollection for the stemlines if use_line_collection: - stemlines = [] stemlines = [((xi, bottom), (xi, yi)) for xi, yi in zip(x, y)] + if linestyle is None: + linestyle = rcParams['lines.linestyle'] stemlines = mcoll.LineCollection(stemlines, linestyles=linestyle, colors=linecolor, label='_nolegend_') diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index b0ea498a93a7..cf29daba9ae3 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -3070,6 +3070,19 @@ def test_stem(use_line_collection): ax.legend() +@check_figures_equal(extensions=['png']) +def test_stem_params(fig_test, fig_ref): + x = np.linspace(0, 3.14, 37) + y = np.sin(x) + + ax = fig_test.subplots() + ax.stem(x, y, linefmt='grey', use_line_collection=True) + + ax = fig_ref.subplots() + with pytest.warns(UserWarning): + ax.stem(x, y, linefmt='grey') + + def test_stem_args(): fig = plt.figure() ax = fig.add_subplot(1, 1, 1)