@@ -2366,11 +2366,14 @@ def stem(self, *args, **kwargs):
23662366 stem(y, linefmt='b-', markerfmt='bo', basefmt='r-')
23672367 stem(x, y, linefmt='b-', markerfmt='bo', basefmt='r-')
23682368
2369- A stem plot plots vertical lines (using *linefmt*) at each *x*
2369+ A stem plot, by default, plots vertical lines (using *linefmt*) at each *x*
23702370 location from the baseline to *y*, and places a marker there
23712371 using *markerfmt*. A horizontal line at 0 is is plotted using
23722372 *basefmt*.
23732373
2374+ It is possible to create a vertically-oriented stem plot
2375+ by providing vertical=True.
2376+
23742377 If no *x* values are provided, the default is (0, 1, ..., len(y) - 1)
23752378
23762379 Return value is a tuple (*markerline*, *stemlines*,
@@ -2419,22 +2422,38 @@ def stem(self, *args, **kwargs):
24192422 except IndexError :
24202423 basefmt = kwargs .pop ('basefmt' , 'r-' )
24212424
2425+ # Check if the user wants a vertical stem plot
2426+ vertical = kwargs .pop ('vertical' , None )
2427+ if vertical is None :
2428+ vertical = False
2429+
24222430 bottom = kwargs .pop ('bottom' , None )
24232431 label = kwargs .pop ('label' , None )
24242432
2425- markerline , = self .plot (x , y , markerfmt , label = "_nolegend_" )
2433+ if vertical :
2434+ markerline , = self .plot (y , x , markerfmt , label = "_nolegend_" )
2435+ else :
2436+ markerline , = self .plot (x , y , markerfmt , label = "_nolegend_" )
24262437
24272438 if bottom is None :
24282439 bottom = 0
24292440
24302441 stemlines = []
24312442 for thisx , thisy in zip (x , y ):
2432- l , = self .plot ([thisx , thisx ], [bottom , thisy ], linefmt ,
2433- label = "_nolegend_" )
2443+ if vertical :
2444+ l , = self .plot ([bottom , thisy ], [thisx , thisx ], linefmt ,
2445+ label = "_nolegend_" )
2446+ else :
2447+ l , = self .plot ([thisx , thisx ], [bottom , thisy ], linefmt ,
2448+ label = "_nolegend_" )
24342449 stemlines .append (l )
24352450
2436- baseline , = self .plot ([np .amin (x ), np .amax (x )], [bottom , bottom ],
2437- basefmt , label = "_nolegend_" )
2451+ if vertical :
2452+ baseline , = self .plot ([bottom , bottom ], [np .amin (x ), np .amax (x )],
2453+ basefmt , label = "_nolegend_" )
2454+ else :
2455+ baseline , = self .plot ([np .amin (x ), np .amax (x )], [bottom , bottom ],
2456+ basefmt , label = "_nolegend_" )
24382457
24392458 self .hold (remember_hold )
24402459
0 commit comments