@@ -3289,7 +3289,7 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
32893289 return mtransforms .Bbox .union (batch )
32903290
32913291 def stem (self , x , y , z , * , linefmt = 'C0-' , markerfmt = 'C0o' , basefmt = 'C3-' ,
3292- bottom = 0 , label = None , zdir = 'z' ):
3292+ bottom = 0 , label = None , orientation = 'z' ):
32933293 """
32943294 Create a 3D stem plot.
32953295
@@ -3300,11 +3300,11 @@ def stem(self, x, y, z, *, linefmt='C0-', markerfmt='C0o', basefmt='C3-',
33003300 Parameters
33013301 ----------
33023302 x, y, z : array-like
3303- The positions of the heads of the stems. The baseline is defined by
3304- two of these positions and *bottom*, and stems are drawn from
3305- *bottom* to the third position . By default, the *x* and *y*
3303+ The positions of the heads of the stems. The stems are drawn along
3304+ the *orientation*-direction from the baseline at *bottom* (in the
3305+ *orientation*-coordinate) to the heads . By default, the *x* and *y*
33063306 positions are used for the baseline and *z* for the head position,
3307- but this can be changed by *zdir *.
3307+ but this can be changed by *orientation *.
33083308
33093309 linefmt : str, default: 'C0-'
33103310 A string defining the properties of the vertical lines. Usually,
@@ -3331,12 +3331,12 @@ def stem(self, x, y, z, *, linefmt='C0-', markerfmt='C0o', basefmt='C3-',
33313331 A format string defining the properties of the baseline.
33323332
33333333 bottom : float, default: 0
3334- The x/y/z- position of the baseline (depending on *zdir*) .
3334+ The position of the baseline, in *orientation*-coordinates .
33353335
33363336 label : str, default: None
33373337 The label to use for the stems in legends.
33383338
3339- zdir : {'x', 'y', 'z'}, default: 'z'
3339+ orientation : {'x', 'y', 'z'}, default: 'z'
33403340 The direction along which stems are drawn.
33413341
33423342 Returns
@@ -3354,37 +3354,50 @@ def stem(self, x, y, z, *, linefmt='C0-', markerfmt='C0o', basefmt='C3-',
33543354
33553355 had_data = self .has_data ()
33563356
3357- jx , jy , jz = art3d . juggle_axes ( x , y , z , zdir )
3357+ _api . check_in_list ([ 'x' , 'y' , 'z' ], orientation = orientation )
33583358
3359- # Plot the baseline in the appropriate plane.
3360- baseline , = self . plot ( x , y , basefmt , zs = bottom , zdir = zdir ,
3361- label = '_nolegend_' )
3359+ xlim = ( np . min ( x ), np . max ( x ))
3360+ ylim = ( np . min ( y ), np . max ( y ))
3361+ zlim = ( np . min ( z ), np . max ( z ) )
33623362
3363- # Plot the stemlines based on the value of zdir.
3364- if zdir [- 1 :] == 'x' :
3363+ # Determine the appropriate plane for the baseline and the direction of
3364+ # stemlines based on the value of orientation.
3365+ if orientation == 'x' :
3366+ basex , basexlim = y , ylim
3367+ basey , baseylim = z , zlim
33653368 lines = [[(bottom , thisy , thisz ), (thisx , thisy , thisz )]
3366- for thisx , thisy , thisz in zip (jx , jy , jz )]
3367- elif zdir [- 1 :] == 'y' :
3369+ for thisx , thisy , thisz in zip (x , y , z )]
3370+ elif orientation == 'y' :
3371+ basex , basexlim = x , xlim
3372+ basey , baseylim = z , zlim
33683373 lines = [[(thisx , bottom , thisz ), (thisx , thisy , thisz )]
3369- for thisx , thisy , thisz in zip (jx , jy , jz )]
3374+ for thisx , thisy , thisz in zip (x , y , z )]
33703375 else :
3376+ basex , basexlim = x , xlim
3377+ basey , baseylim = y , ylim
33713378 lines = [[(thisx , thisy , bottom ), (thisx , thisy , thisz )]
3372- for thisx , thisy , thisz in zip (jx , jy , jz )]
3379+ for thisx , thisy , thisz in zip (x , y , z )]
3380+
3381+ # Determine style for stem lines.
33733382 linestyle , linemarker , linecolor = _process_plot_format (linefmt )
33743383 if linestyle is None :
33753384 linestyle = rcParams ['lines.linestyle' ]
3385+
3386+ # Plot everything in required order.
3387+ baseline , = self .plot (basex , basey , basefmt , zs = bottom ,
3388+ zdir = orientation , label = '_nolegend_' )
33763389 stemlines = art3d .Line3DCollection (
33773390 lines , linestyles = linestyle , colors = linecolor , label = '_nolegend_' )
33783391 self .add_collection (stemlines )
3379-
3380- markerline , = self .plot (x , y , z , markerfmt , zdir = zdir ,
3381- label = '_nolegend_' )
3392+ markerline , = self .plot (x , y , z , markerfmt , label = '_nolegend_' )
33823393
33833394 stem_container = StemContainer ((markerline , stemlines , baseline ),
33843395 label = label )
33853396 self .add_container (stem_container )
33863397
3387- self .auto_scale_xyz (jx , jy , jz , had_data )
3398+ jx , jy , jz = art3d .juggle_axes (basexlim , baseylim , [bottom , bottom ],
3399+ orientation )
3400+ self .auto_scale_xyz ([* jx , * xlim ], [* jy , * ylim ], [* jz , * zlim ], had_data )
33883401
33893402 return stem_container
33903403
0 commit comments