@@ -2727,23 +2727,28 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
2727
2727
"""
2728
2728
Create a stem plot.
2729
2729
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.
2732
2735
2733
2736
Call signature::
2734
2737
2735
- stem([x ,] y , linefmt=None, markerfmt=None, basefmt=None)
2738
+ stem([locs ,] heads , linefmt=None, markerfmt=None, basefmt=None)
2736
2739
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.
2739
2742
2740
2743
Parameters
2741
2744
----------
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.
2744
2748
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.
2747
2752
2748
2753
linefmt : str, optional
2749
2754
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,
2774
2779
basefmt : str, default: 'C3-' ('C2-' in classic mode)
2775
2780
A format string defining the properties of the baseline.
2776
2781
2777
- orientation : string, optional ( horizontal)
2782
+ orientation : str, default: ' horizontal'
2778
2783
If 'vertical', will produce a vertically-oriented stem plot,
2779
2784
else it will produce a horizontally-oriented stem plot.
2780
2785
@@ -2811,15 +2816,20 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
2811
2816
orientation = orientation )
2812
2817
2813
2818
if len (args ) == 1 :
2814
- y , = args
2815
- x = np .arange (len (y ))
2819
+ heads , = args
2820
+ locs = np .arange (len (heads ))
2816
2821
args = ()
2817
2822
else :
2818
- x , y , * args = args
2823
+ locs , heads , * args = args
2819
2824
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 )
2823
2833
2824
2834
# defaults for formats
2825
2835
if linefmt is None :
@@ -2868,16 +2878,14 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
2868
2878
else :
2869
2879
basestyle , basemarker , basecolor = _process_plot_format (basefmt )
2870
2880
2871
- # Check if the user wants a vertical stem plot
2872
- if orientation == 'vertical' :
2873
- x , y = y , x
2874
-
2875
2881
# New behaviour in 3.1 is to use a LineCollection for the stemlines
2876
2882
if use_line_collection :
2877
2883
if orientation == 'vertical' :
2878
- stemlines = [((bottom , yi ), (xi , yi )) for xi , yi in zip (x , y )]
2884
+ stemlines = [
2885
+ ((bottom , li ), (hi , li )) for li , hi in zip (locs , heads )]
2879
2886
else :
2880
- stemlines = [((xi , bottom ), (xi , yi )) for xi , yi in zip (x , y )]
2887
+ stemlines = [
2888
+ ((li , bottom ), (li , hi )) for li , hi in zip (locs , heads )]
2881
2889
if linestyle is None :
2882
2890
linestyle = rcParams ['lines.linestyle' ]
2883
2891
stemlines = mcoll .LineCollection (stemlines , linestyles = linestyle ,
@@ -2887,28 +2895,35 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
2887
2895
# Old behaviour is to plot each of the lines individually
2888
2896
else :
2889
2897
stemlines = []
2890
- for xi , yi in zip (x , y ):
2898
+ for li , hi in zip (locs , heads ):
2891
2899
if orientation == 'vertical' :
2892
- xs = [bottom , xi ]
2893
- ys = [yi , yi ]
2900
+ xs = [bottom , hi ]
2901
+ ys = [li , li ]
2894
2902
else :
2895
- xs = [xi , xi ]
2896
- ys = [bottom , yi ]
2903
+ xs = [li , li ]
2904
+ ys = [bottom , hi ]
2897
2905
l , = self .plot (xs , ys ,
2898
2906
color = linecolor , linestyle = linestyle ,
2899
2907
marker = linemarker , label = "_nolegend_" )
2900
2908
stemlines .append (l )
2901
2909
2902
- markerline , = self .plot (x , y , color = markercolor , linestyle = markerstyle ,
2903
- marker = markermarker , label = "_nolegend_" )
2910
+ if orientation == 'vertical' :
2911
+ markerline , = self .plot (heads , locs , color = markercolor ,
2912
+ linestyle = markerstyle , marker = markermarker ,
2913
+ label = "_nolegend_" )
2914
+ else :
2915
+ markerline , = self .plot (locs , heads , color = markercolor ,
2916
+ linestyle = markerstyle , marker = markermarker ,
2917
+ label = "_nolegend_" )
2904
2918
2905
2919
if orientation == 'vertical' :
2906
- x , y = y , x
2907
- baseline , = self . plot ([ bottom , bottom ], [np .min (x ), np .max (x )],
2920
+ baseline , = self . plot ([ bottom , bottom ],
2921
+ [np .min (locs ), np .max (locs )],
2908
2922
color = basecolor , linestyle = basestyle ,
2909
2923
marker = basemarker , label = "_nolegend_" )
2910
2924
else :
2911
- baseline , = self .plot ([np .min (x ), np .max (x )], [bottom , bottom ],
2925
+ baseline , = self .plot ([np .min (locs ), np .max (locs )],
2926
+ [bottom , bottom ],
2912
2927
color = basecolor , linestyle = basestyle ,
2913
2928
marker = basemarker , label = "_nolegend_" )
2914
2929
0 commit comments