@@ -2723,7 +2723,7 @@ def broken_barh(self, xranges, yrange, **kwargs):
2723
2723
2724
2724
@_preprocess_data ()
2725
2725
def stem (self , * args , linefmt = None , markerfmt = None , basefmt = None , bottom = 0 ,
2726
- label = None , use_line_collection = True ):
2726
+ label = None , use_line_collection = True , vertical = False ):
2727
2727
"""
2728
2728
Create a stem plot.
2729
2729
@@ -2774,6 +2774,9 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
2774
2774
basefmt : str, default: 'C3-' ('C2-' in classic mode)
2775
2775
A format string defining the properties of the baseline.
2776
2776
2777
+ vertical : bool, optional (False)
2778
+ If 'True', will produce a vertically-oriented stem plot.
2779
+
2777
2780
bottom : float, default: 0
2778
2781
The y-position of the baseline.
2779
2782
@@ -2862,9 +2865,16 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
2862
2865
else :
2863
2866
basestyle , basemarker , basecolor = _process_plot_format (basefmt )
2864
2867
2868
+ # Check if the user wants a vertical stem plot
2869
+ if vertical :
2870
+ x , y = y , x
2871
+
2865
2872
# New behaviour in 3.1 is to use a LineCollection for the stemlines
2866
2873
if use_line_collection :
2867
- stemlines = [((xi , bottom ), (xi , yi )) for xi , yi in zip (x , y )]
2874
+ if vertical :
2875
+ stemlines = [((bottom , yi ), (xi , yi )) for xi , yi in zip (x , y )]
2876
+ else :
2877
+ stemlines = [((xi , bottom ), (xi , yi )) for xi , yi in zip (x , y )]
2868
2878
if linestyle is None :
2869
2879
linestyle = rcParams ['lines.linestyle' ]
2870
2880
stemlines = mcoll .LineCollection (stemlines , linestyles = linestyle ,
@@ -2875,17 +2885,27 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
2875
2885
else :
2876
2886
stemlines = []
2877
2887
for xi , yi in zip (x , y ):
2878
- l , = self .plot ([xi , xi ], [bottom , yi ],
2888
+ if vertical :
2889
+ xs = [bottom , xi ]
2890
+ ys = [yi , yi ]
2891
+ else :
2892
+ xs = [xi , xi ]
2893
+ ys = [bottom , yi ]
2894
+ l , = self .plot (xs , ys ,
2879
2895
color = linecolor , linestyle = linestyle ,
2880
2896
marker = linemarker , label = "_nolegend_" )
2881
2897
stemlines .append (l )
2882
2898
2883
2899
markerline , = self .plot (x , y , color = markercolor , linestyle = markerstyle ,
2884
2900
marker = markermarker , label = "_nolegend_" )
2885
-
2886
- baseline , = self .plot ([np .min (x ), np .max (x )], [bottom , bottom ],
2887
- color = basecolor , linestyle = basestyle ,
2888
- marker = basemarker , label = "_nolegend_" )
2901
+ if vertical :
2902
+ baseline , = self .plot ([bottom , bottom ], [np .min (x ), np .max (x )],
2903
+ color = basecolor , linestyle = basestyle ,
2904
+ marker = basemarker , label = "_nolegend_" )
2905
+ else :
2906
+ baseline , = self .plot ([np .min (x ), np .max (x )], [bottom , bottom ],
2907
+ color = basecolor , linestyle = basestyle ,
2908
+ marker = basemarker , label = "_nolegend_" )
2889
2909
2890
2910
stem_container = StemContainer ((markerline , stemlines , baseline ),
2891
2911
label = label )
0 commit comments