Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aa5af77

Browse files
committed
Cleanup stem docs and simplify implementation.
On the implementation side, we can use `vlines`/`hlines` to generate the correct `LineCollection`. On the documentation side, it seems perfectly valid to only specify a linestyle and no color in `linefmt` (e.g. `stem([0, 1], [2, 3], linefmt="-.")` works just fine). On the other hand markers are indeed silently dropped (possibly we could emit a warning there, but that should be another PR). So reword accordingly; and also slighly reword the doc for `markerfmt`.
1 parent 02af61b commit aa5af77

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,8 +2614,7 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
26142614
For horizontal stem plots, the x-values of the stem heads.
26152615
26162616
linefmt : str, optional
2617-
A string defining the properties of the vertical lines. Usually,
2618-
this will be a color or a color and a linestyle:
2617+
A string defining the color and/or linestyle of the vertical lines:
26192618
26202619
========= =============
26212620
Character Line Style
@@ -2629,15 +2628,14 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
26292628
Default: 'C0-', i.e. solid line with the first color of the color
26302629
cycle.
26312630
2632-
Note: While it is technically possible to specify valid formats
2633-
other than color or color and linestyle (e.g. 'rx' or '-.'), this
2634-
is beyond the intention of the method and will most likely not
2635-
result in a reasonable plot.
2631+
Note: Markers specified through this parameter (e.g. 'x') will be
2632+
silently ignored (unless using ``use_line_collection=False``).
2633+
Instead, markers should be specified using *markerfmt*.
26362634
26372635
markerfmt : str, optional
2638-
A string defining the properties of the markers at the stem heads.
2639-
Default: 'C0o', i.e. filled circles with the first color of the
2640-
color cycle.
2636+
A string defining the color and/or shape of the markers at the stem
2637+
heads. Default: 'C0o', i.e. filled circles with the first color of
2638+
the color cycle.
26412639
26422640
basefmt : str, default: 'C3-' ('C2-' in classic mode)
26432641
A format string defining the properties of the baseline.
@@ -2738,20 +2736,12 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
27382736

27392737
# New behaviour in 3.1 is to use a LineCollection for the stemlines
27402738
if use_line_collection:
2741-
if orientation == 'horizontal':
2742-
stemlines = [
2743-
((bottom, loc), (head, loc))
2744-
for loc, head in zip(locs, heads)]
2745-
else:
2746-
stemlines = [
2747-
((loc, bottom), (loc, head))
2748-
for loc, head in zip(locs, heads)]
27492739
if linestyle is None:
27502740
linestyle = rcParams['lines.linestyle']
2751-
stemlines = mcoll.LineCollection(stemlines, linestyles=linestyle,
2752-
colors=linecolor,
2753-
label='_nolegend_')
2754-
self.add_collection(stemlines)
2741+
xlines = self.vlines if orientation == "vertical" else self.hlines
2742+
stemlines = xlines(
2743+
locs, bottom, heads,
2744+
colors=linecolor, linestyles=linestyle, label="_nolegend_")
27552745
# Old behaviour is to plot each of the lines individually
27562746
else:
27572747
stemlines = []

0 commit comments

Comments
 (0)