@@ -2727,23 +2727,28 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
27272727 """
27282728 Create a stem plot.
27292729
2730- A stem plot plots vertical lines at each *x* location from the baseline
2731- to *y*, and places a marker there.
2730+ A stem plot draws lines perpendicular to a baseline at each location
2731+ *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
2734+ *y* positions, and the *heads* are *x* values.
27322735
27332736 Call signature::
27342737
2735- stem([x ,] y , linefmt=None, markerfmt=None, basefmt=None)
2738+ stem([locs ,] heads , linefmt=None, markerfmt=None, basefmt=None)
27362739
2737- The x -positions are optional. The formats may be provided either as
2738- positional or as keyword-arguments.
2740+ The *locs* -positions are optional. The formats may be provided either
2741+ as positional or as keyword-arguments.
27392742
27402743 Parameters
27412744 ----------
2742- x : array-like, optional
2743- The x-positions of the stems. Default: (0, 1, ..., len(y) - 1).
2745+ 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.
27442748
2745- y : array-like
2746- The y-values of the stem heads.
2749+ 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.
27472752
27482753 linefmt : str, optional
27492754 A string defining the properties of the vertical lines. Usually,
@@ -2774,7 +2779,7 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
27742779 basefmt : str, default: 'C3-' ('C2-' in classic mode)
27752780 A format string defining the properties of the baseline.
27762781
2777- orientation : string, optional ( horizontal)
2782+ orientation : str, default: ' horizontal'
27782783 If 'vertical', will produce a vertically-oriented stem plot,
27792784 else it will produce a horizontally-oriented stem plot.
27802785
@@ -2811,15 +2816,20 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
28112816 orientation = orientation )
28122817
28132818 if len (args ) == 1 :
2814- y , = args
2815- x = np .arange (len (y ))
2819+ heads , = args
2820+ locs = np .arange (len (heads ))
28162821 args = ()
28172822 else :
2818- x , y , * args = args
2823+ locs , heads , * args = args
28192824
2820- self ._process_unit_info (xdata = x , ydata = y )
2821- x = self .convert_xunits (x )
2822- y = self .convert_yunits (y )
2825+ if orientation == 'horizontal' :
2826+ self ._process_unit_info (xdata = locs , ydata = heads )
2827+ locs = self .convert_xunits (locs )
2828+ heads = self .convert_yunits (heads )
2829+ else :
2830+ self ._process_unit_info (xdata = heads , ydata = locs )
2831+ heads = self .convert_xunits (heads )
2832+ locs = self .convert_yunits (locs )
28232833
28242834 # defaults for formats
28252835 if linefmt is None :
@@ -2868,16 +2878,16 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
28682878 else :
28692879 basestyle , basemarker , basecolor = _process_plot_format (basefmt )
28702880
2871- # Check if the user wants a vertical stem plot
2872- if orientation == 'vertical' :
2873- x , y = y , x
2874-
28752881 # New behaviour in 3.1 is to use a LineCollection for the stemlines
28762882 if use_line_collection :
28772883 if orientation == 'vertical' :
2878- stemlines = [((bottom , yi ), (xi , yi )) for xi , yi in zip (x , y )]
2884+ stemlines = [
2885+ ((bottom , loc ), (head , loc ))
2886+ for loc , head in zip (locs , heads )]
28792887 else :
2880- stemlines = [((xi , bottom ), (xi , yi )) for xi , yi in zip (x , y )]
2888+ stemlines = [
2889+ ((loc , bottom ), (loc , head ))
2890+ for loc , head in zip (locs , heads )]
28812891 if linestyle is None :
28822892 linestyle = rcParams ['lines.linestyle' ]
28832893 stemlines = mcoll .LineCollection (stemlines , linestyles = linestyle ,
@@ -2887,30 +2897,36 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
28872897 # Old behaviour is to plot each of the lines individually
28882898 else :
28892899 stemlines = []
2890- for xi , yi in zip (x , y ):
2900+ for loc , head in zip (locs , heads ):
28912901 if orientation == 'vertical' :
2892- xs = [bottom , xi ]
2893- ys = [yi , yi ]
2902+ xs = [bottom , head ]
2903+ ys = [loc , loc ]
28942904 else :
2895- xs = [xi , xi ]
2896- ys = [bottom , yi ]
2905+ xs = [loc , loc ]
2906+ ys = [bottom , head ]
28972907 l , = self .plot (xs , ys ,
28982908 color = linecolor , linestyle = linestyle ,
28992909 marker = linemarker , label = "_nolegend_" )
29002910 stemlines .append (l )
29012911
2902- markerline , = self .plot (x , y , color = markercolor , linestyle = markerstyle ,
2903- marker = markermarker , label = "_nolegend_" )
2904-
29052912 if orientation == 'vertical' :
2906- x , y = y , x
2907- baseline , = self . plot ([ bottom , bottom ], [ np . min ( x ), np . max ( x )],
2908- color = basecolor , linestyle = basestyle ,
2909- marker = basemarker , label = "_nolegend_" )
2913+ marker_x = heads
2914+ marker_y = locs
2915+ baseline_x = [ bottom , bottom ]
2916+ baseline_y = [ np . min ( locs ), np . max ( locs )]
29102917 else :
2911- baseline , = self .plot ([np .min (x ), np .max (x )], [bottom , bottom ],
2912- color = basecolor , linestyle = basestyle ,
2913- marker = basemarker , label = "_nolegend_" )
2918+ marker_x = locs
2919+ marker_y = heads
2920+ baseline_x = [np .min (locs ), np .max (locs )]
2921+ baseline_y = [bottom , bottom ]
2922+
2923+ markerline , = self .plot (marker_x , marker_y ,
2924+ color = markercolor , linestyle = markerstyle ,
2925+ marker = markermarker , label = "_nolegend_" )
2926+
2927+ baseline , = self .plot (baseline_x , baseline_y ,
2928+ color = basecolor , linestyle = basestyle ,
2929+ marker = basemarker , label = "_nolegend_" )
29142930
29152931 stem_container = StemContainer ((markerline , stemlines , baseline ),
29162932 label = label )
0 commit comments