Skip to content

Commit 99e7ede

Browse files
committed
Improve stem orientation tests and what's new doc.
1 parent c022b22 commit 99e7ede

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

doc/users/next_whats_new/stem_orientation.rst

+18-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,22 @@ Added *orientation* parameter for stem plots
33
When creating stem plots, you can now pass in an *orientation* argument to
44
`.Axes.stem` or `.pyplot.stem`.
55

6-
Currently, only ``'vertical'`` and ``'horizontal'`` orientations are supported,
7-
with ``'vertical'`` being the default.
6+
The default orientation produces stem lines that are vertically oriented:
87

9-
Example
10-
```````
11-
stem(x, x, orientation='horizontal')
8+
.. plot::
9+
10+
locs = np.linspace(0.1, 2 * np.pi, 25)
11+
heads = np.cos(locs)
12+
13+
fig, ax = plt.subplots()
14+
ax.stem(locs, heads)
15+
16+
With the ``'horizontal'`` orientation, the stem lines will be horizontal:
17+
18+
.. plot::
19+
20+
locs = np.linspace(0.1, 2 * np.pi, 25)
21+
heads = np.cos(locs)
22+
23+
fig, ax = plt.subplots()
24+
ax.stem(locs, heads, orientation='horizontal')

lib/matplotlib/tests/test_axes.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -3245,14 +3245,13 @@ def test_hist_stacked_weighted():
32453245
@image_comparison(['stem.png'], style='mpl20', remove_text=True)
32463246
def test_stem(use_line_collection):
32473247
x = np.linspace(0.1, 2 * np.pi, 100)
3248-
args = (x, np.cos(x))
3249-
# Label is a single space to force a legend to be drawn, but to avoid any
3250-
# text being drawn
3251-
kwargs = dict(linefmt='C2-.', markerfmt='k+', basefmt='C1-.',
3252-
label=' ', use_line_collection=use_line_collection)
32533248

32543249
fig, ax = plt.subplots()
3255-
ax.stem(*args, **kwargs)
3250+
# Label is a single space to force a legend to be drawn, but to avoid any
3251+
# text being drawn
3252+
ax.stem(x, np.cos(x),
3253+
linefmt='C2-.', markerfmt='k+', basefmt='C1-.', label=' ',
3254+
use_line_collection=use_line_collection)
32563255

32573256
ax.legend()
32583257

@@ -3284,12 +3283,11 @@ def test_stem_dates():
32843283
@image_comparison(['stem_orientation.png'], style='mpl20', remove_text=True)
32853284
def test_stem_orientation(use_line_collection):
32863285
x = np.linspace(0.1, 2*np.pi, 50)
3287-
args = (x, np.cos(x))
3288-
kwargs = dict(linefmt='C2-.', markerfmt='kx', basefmt='C1-.',
3289-
use_line_collection=use_line_collection)
32903286

32913287
fig, ax = plt.subplots()
3292-
ax.stem(*args, **kwargs, orientation='horizontal')
3288+
ax.stem(x, np.cos(x),
3289+
linefmt='C2-.', markerfmt='kx', basefmt='C1-.',
3290+
use_line_collection=use_line_collection, orientation='horizontal')
32933291

32943292

32953293
@image_comparison(['hist_stacked_stepfilled_alpha'])

0 commit comments

Comments
 (0)