From bc6e26f852a77cf934652537251f19d4be8a4412 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 24 Mar 2019 02:47:24 -0400 Subject: [PATCH] Backport PR #13745: Fix stem(use_line_collection) --- lib/matplotlib/axes/_axes.py | 3 ++- lib/matplotlib/tests/test_axes.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index ca9e94ef0254..ba9d507827a9 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 a5e2689ecb16..34d9cc66e709 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)