Skip to content

Commit c022b22

Browse files
committed
Flip meaning of orientation in stem().
1 parent 54258c9 commit c022b22

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

doc/users/next_whats_new/stem_orientation.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ When creating stem plots, you can now pass in an *orientation* argument to
44
`.Axes.stem` or `.pyplot.stem`.
55

66
Currently, only ``'vertical'`` and ``'horizontal'`` orientations are supported,
7-
with ``'horizontal'`` being the default.
7+
with ``'vertical'`` being the default.
88

99
Example
1010
```````
11-
stem(x, x, orientation='vertical')
11+
stem(x, x, orientation='horizontal')

lib/matplotlib/axes/_axes.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2723,14 +2723,14 @@ def broken_barh(self, xranges, yrange, **kwargs):
27232723

27242724
@_preprocess_data()
27252725
def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
2726-
label=None, use_line_collection=True, orientation='horizontal'):
2726+
label=None, use_line_collection=True, orientation='vertical'):
27272727
"""
27282728
Create a stem plot.
27292729
27302730
A stem plot draws lines perpendicular to a baseline at each location
27312731
*locs* from the baseline to *heads*, and places a marker there. For
2732-
horizontal stem plots (the default), the *locs* are *x* positions, and
2733-
the *heads* are *y* values. For vertical stem plots, the *locs* are
2732+
vertical stem plots (the default), the *locs* are *x* positions, and
2733+
the *heads* are *y* values. For horizontal stem plots, the *locs* are
27342734
*y* positions, and the *heads* are *x* values.
27352735
27362736
Call signature::
@@ -2743,12 +2743,12 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
27432743
Parameters
27442744
----------
27452745
locs : array-like, default: (0, 1, ..., len(heads) - 1)
2746-
For horizontal stem plots, the x-positions of the stems.
2747-
For vertical stem plots, the y-positions of the stems.
2746+
For vertical stem plots, the x-positions of the stems.
2747+
For horizontal stem plots, the y-positions of the stems.
27482748
27492749
heads : array-like
2750-
For horizontal stem plots, the y-values of the stem heads.
2751-
For vertical stem plots, the x-values of the stem heads.
2750+
For vertical stem plots, the y-values of the stem heads.
2751+
For horizontal stem plots, the x-values of the stem heads.
27522752
27532753
linefmt : str, optional
27542754
A string defining the properties of the vertical lines. Usually,
@@ -2779,12 +2779,12 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
27792779
basefmt : str, default: 'C3-' ('C2-' in classic mode)
27802780
A format string defining the properties of the baseline.
27812781
2782-
orientation : str, default: 'horizontal'
2783-
If 'vertical', will produce a vertically-oriented stem plot,
2784-
else it will produce a horizontally-oriented stem plot.
2782+
orientation : str, default: 'vertical'
2783+
If 'vertical', will produce a plot with stems oriented vertically,
2784+
otherwise the stems will be oriented horizontally.
27852785
27862786
bottom : float, default: 0
2787-
The y-position of the baseline.
2787+
The y/x-position of the baseline (depending on orientation).
27882788
27892789
label : str, default: None
27902790
The label to use for the stems in legends.
@@ -2822,7 +2822,7 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
28222822
else:
28232823
locs, heads, *args = args
28242824

2825-
if orientation == 'horizontal':
2825+
if orientation == 'vertical':
28262826
self._process_unit_info(xdata=locs, ydata=heads)
28272827
locs = self.convert_xunits(locs)
28282828
heads = self.convert_yunits(heads)
@@ -2880,7 +2880,7 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
28802880

28812881
# New behaviour in 3.1 is to use a LineCollection for the stemlines
28822882
if use_line_collection:
2883-
if orientation == 'vertical':
2883+
if orientation == 'horizontal':
28842884
stemlines = [
28852885
((bottom, loc), (head, loc))
28862886
for loc, head in zip(locs, heads)]
@@ -2898,7 +2898,7 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
28982898
else:
28992899
stemlines = []
29002900
for loc, head in zip(locs, heads):
2901-
if orientation == 'vertical':
2901+
if orientation == 'horizontal':
29022902
xs = [bottom, head]
29032903
ys = [loc, loc]
29042904
else:
@@ -2909,7 +2909,7 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
29092909
marker=linemarker, label="_nolegend_")
29102910
stemlines.append(l)
29112911

2912-
if orientation == 'vertical':
2912+
if orientation == 'horizontal':
29132913
marker_x = heads
29142914
marker_y = locs
29152915
baseline_x = [bottom, bottom]

lib/matplotlib/pyplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3018,8 +3018,8 @@ def stackplot(
30183018
@_copy_docstring_and_deprecators(Axes.stem)
30193019
def stem(
30203020
*args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
3021-
label=None, use_line_collection=True,
3022-
orientation='horizontal', data=None):
3021+
label=None, use_line_collection=True, orientation='vertical',
3022+
data=None):
30233023
return gca().stem(
30243024
*args, linefmt=linefmt, markerfmt=markerfmt, basefmt=basefmt,
30253025
bottom=bottom, label=label,

lib/matplotlib/tests/test_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3289,7 +3289,7 @@ def test_stem_orientation(use_line_collection):
32893289
use_line_collection=use_line_collection)
32903290

32913291
fig, ax = plt.subplots()
3292-
ax.stem(*args, **kwargs, orientation='vertical')
3292+
ax.stem(*args, **kwargs, orientation='horizontal')
32933293

32943294

32953295
@image_comparison(['hist_stacked_stepfilled_alpha'])

0 commit comments

Comments
 (0)