@@ -3276,7 +3276,7 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
3276
3276
return mtransforms .Bbox .union (batch )
3277
3277
3278
3278
def stem (self , x , y , z , * , linefmt = 'C0-' , markerfmt = 'C0o' , basefmt = 'C3-' ,
3279
- bottom = 0 , label = None , zdir = 'z' ):
3279
+ bottom = 0 , label = None , orientation = 'z' ):
3280
3280
"""
3281
3281
Create a 3D stem plot.
3282
3282
@@ -3287,11 +3287,11 @@ def stem(self, x, y, z, *, linefmt='C0-', markerfmt='C0o', basefmt='C3-',
3287
3287
Parameters
3288
3288
----------
3289
3289
x, y, z : array-like
3290
- The positions of the heads of the stems. The baseline is defined by
3291
- two of these positions and *bottom*, and stems are drawn from
3292
- *bottom* to the third position . By default, the *x* and *y*
3290
+ The positions of the heads of the stems. The stems are drawn along
3291
+ the *orientation*-direction from the baseline at *bottom* (in the
3292
+ *orientation*-coordinate) to the heads . By default, the *x* and *y*
3293
3293
positions are used for the baseline and *z* for the head position,
3294
- but this can be changed by *zdir *.
3294
+ but this can be changed by *orientation *.
3295
3295
3296
3296
linefmt : str, default: 'C0-'
3297
3297
A string defining the properties of the vertical lines. Usually,
@@ -3318,12 +3318,12 @@ def stem(self, x, y, z, *, linefmt='C0-', markerfmt='C0o', basefmt='C3-',
3318
3318
A format string defining the properties of the baseline.
3319
3319
3320
3320
bottom : float, default: 0
3321
- The x/y/z- position of the baseline (depending on *zdir*) .
3321
+ The position of the baseline, in *orientation*-coordinates .
3322
3322
3323
3323
label : str, default: None
3324
3324
The label to use for the stems in legends.
3325
3325
3326
- zdir : {'x', 'y', 'z'}, default: 'z'
3326
+ orientation : {'x', 'y', 'z'}, default: 'z'
3327
3327
The direction along which stems are drawn.
3328
3328
3329
3329
Returns
@@ -3341,37 +3341,50 @@ def stem(self, x, y, z, *, linefmt='C0-', markerfmt='C0o', basefmt='C3-',
3341
3341
3342
3342
had_data = self .has_data ()
3343
3343
3344
- jx , jy , jz = art3d . juggle_axes ( x , y , z , zdir )
3344
+ cbook . _check_in_list ([ 'x' , 'y' , 'z' ], orientation = orientation )
3345
3345
3346
- # Plot the baseline in the appropriate plane.
3347
- baseline , = self . plot ( x , y , basefmt , zs = bottom , zdir = zdir ,
3348
- label = '_nolegend_' )
3346
+ xlim = ( np . min ( x ), np . max ( x ))
3347
+ ylim = ( np . min ( y ), np . max ( y ))
3348
+ zlim = ( np . min ( z ), np . max ( z ) )
3349
3349
3350
- # Plot the stemlines based on the value of zdir.
3351
- if zdir [- 1 :] == 'x' :
3350
+ # Determine the appropriate plane for the baseline and the direction of
3351
+ # stemlines based on the value of orientation.
3352
+ if orientation == 'x' :
3353
+ basex , basexlim = y , ylim
3354
+ basey , baseylim = z , zlim
3352
3355
lines = [[(bottom , thisy , thisz ), (thisx , thisy , thisz )]
3353
- for thisx , thisy , thisz in zip (jx , jy , jz )]
3354
- elif zdir [- 1 :] == 'y' :
3356
+ for thisx , thisy , thisz in zip (x , y , z )]
3357
+ elif orientation == 'y' :
3358
+ basex , basexlim = x , xlim
3359
+ basey , baseylim = z , zlim
3355
3360
lines = [[(thisx , bottom , thisz ), (thisx , thisy , thisz )]
3356
- for thisx , thisy , thisz in zip (jx , jy , jz )]
3361
+ for thisx , thisy , thisz in zip (x , y , z )]
3357
3362
else :
3363
+ basex , basexlim = x , xlim
3364
+ basey , baseylim = y , ylim
3358
3365
lines = [[(thisx , thisy , bottom ), (thisx , thisy , thisz )]
3359
- for thisx , thisy , thisz in zip (jx , jy , jz )]
3366
+ for thisx , thisy , thisz in zip (x , y , z )]
3367
+
3368
+ # Determine style for stem lines.
3360
3369
linestyle , linemarker , linecolor = _process_plot_format (linefmt )
3361
3370
if linestyle is None :
3362
3371
linestyle = rcParams ['lines.linestyle' ]
3372
+
3373
+ # Plot everything in required order.
3374
+ baseline , = self .plot (basex , basey , basefmt , zs = bottom ,
3375
+ zdir = orientation , label = '_nolegend_' )
3363
3376
stemlines = art3d .Line3DCollection (
3364
3377
lines , linestyles = linestyle , colors = linecolor , label = '_nolegend_' )
3365
3378
self .add_collection (stemlines )
3366
-
3367
- markerline , = self .plot (x , y , z , markerfmt , zdir = zdir ,
3368
- label = '_nolegend_' )
3379
+ markerline , = self .plot (x , y , z , markerfmt , label = '_nolegend_' )
3369
3380
3370
3381
stem_container = StemContainer ((markerline , stemlines , baseline ),
3371
3382
label = label )
3372
3383
self .add_container (stem_container )
3373
3384
3374
- self .auto_scale_xyz (jx , jy , jz , had_data )
3385
+ jx , jy , jz = art3d .juggle_axes (basexlim , baseylim , [bottom , bottom ],
3386
+ orientation )
3387
+ self .auto_scale_xyz ([* jx , * xlim ], [* jy , * ylim ], [* jz , * zlim ], had_data )
3375
3388
3376
3389
return stem_container
3377
3390
0 commit comments