@@ -3351,6 +3351,121 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
33513351 batch .append (axis_bb )
33523352 return mtransforms .Bbox .union (batch )
33533353
3354+ def stem (self , x , y , z , * , linefmt = 'C0-' , markerfmt = 'C0o' , basefmt = 'C3-' ,
3355+ bottom = 0 , label = None , orientation = 'z' ):
3356+ """
3357+ Create a 3D stem plot.
3358+
3359+ A stem plot draws lines perpendicular to a baseline, and places markers
3360+ at the heads. By default, the baseline is defined by *x* and *y*, and
3361+ stems are drawn vertically from *bottom* to *z*.
3362+
3363+ Parameters
3364+ ----------
3365+ x, y, z : array-like
3366+ The positions of the heads of the stems. The stems are drawn along
3367+ the *orientation*-direction from the baseline at *bottom* (in the
3368+ *orientation*-coordinate) to the heads. By default, the *x* and *y*
3369+ positions are used for the baseline and *z* for the head position,
3370+ but this can be changed by *orientation*.
3371+
3372+ linefmt : str, default: 'C0-'
3373+ A string defining the properties of the vertical lines. Usually,
3374+ this will be a color or a color and a linestyle:
3375+
3376+ ========= =============
3377+ Character Line Style
3378+ ========= =============
3379+ ``'-'`` solid line
3380+ ``'--'`` dashed line
3381+ ``'-.'`` dash-dot line
3382+ ``':'`` dotted line
3383+ ========= =============
3384+
3385+ Note: While it is technically possible to specify valid formats
3386+ other than color or color and linestyle (e.g. 'rx' or '-.'), this
3387+ is beyond the intention of the method and will most likely not
3388+ result in a reasonable plot.
3389+
3390+ markerfmt : str, default: 'C0o'
3391+ A string defining the properties of the markers at the stem heads.
3392+
3393+ basefmt : str, default: 'C3-'
3394+ A format string defining the properties of the baseline.
3395+
3396+ bottom : float, default: 0
3397+ The position of the baseline, in *orientation*-coordinates.
3398+
3399+ label : str, default: None
3400+ The label to use for the stems in legends.
3401+
3402+ orientation : {'x', 'y', 'z'}, default: 'z'
3403+ The direction along which stems are drawn.
3404+
3405+ Returns
3406+ -------
3407+ `.StemContainer`
3408+ The container may be treated like a tuple
3409+ (*markerline*, *stemlines*, *baseline*)
3410+
3411+ Examples
3412+ --------
3413+ .. plot:: gallery/mplot3d/stem3d_demo.py
3414+ """
3415+
3416+ from matplotlib .container import StemContainer
3417+
3418+ had_data = self .has_data ()
3419+
3420+ _api .check_in_list (['x' , 'y' , 'z' ], orientation = orientation )
3421+
3422+ xlim = (np .min (x ), np .max (x ))
3423+ ylim = (np .min (y ), np .max (y ))
3424+ zlim = (np .min (z ), np .max (z ))
3425+
3426+ # Determine the appropriate plane for the baseline and the direction of
3427+ # stemlines based on the value of orientation.
3428+ if orientation == 'x' :
3429+ basex , basexlim = y , ylim
3430+ basey , baseylim = z , zlim
3431+ lines = [[(bottom , thisy , thisz ), (thisx , thisy , thisz )]
3432+ for thisx , thisy , thisz in zip (x , y , z )]
3433+ elif orientation == 'y' :
3434+ basex , basexlim = x , xlim
3435+ basey , baseylim = z , zlim
3436+ lines = [[(thisx , bottom , thisz ), (thisx , thisy , thisz )]
3437+ for thisx , thisy , thisz in zip (x , y , z )]
3438+ else :
3439+ basex , basexlim = x , xlim
3440+ basey , baseylim = y , ylim
3441+ lines = [[(thisx , thisy , bottom ), (thisx , thisy , thisz )]
3442+ for thisx , thisy , thisz in zip (x , y , z )]
3443+
3444+ # Determine style for stem lines.
3445+ linestyle , linemarker , linecolor = _process_plot_format (linefmt )
3446+ if linestyle is None :
3447+ linestyle = rcParams ['lines.linestyle' ]
3448+
3449+ # Plot everything in required order.
3450+ baseline , = self .plot (basex , basey , basefmt , zs = bottom ,
3451+ zdir = orientation , label = '_nolegend_' )
3452+ stemlines = art3d .Line3DCollection (
3453+ lines , linestyles = linestyle , colors = linecolor , label = '_nolegend_' )
3454+ self .add_collection (stemlines )
3455+ markerline , = self .plot (x , y , z , markerfmt , label = '_nolegend_' )
3456+
3457+ stem_container = StemContainer ((markerline , stemlines , baseline ),
3458+ label = label )
3459+ self .add_container (stem_container )
3460+
3461+ jx , jy , jz = art3d .juggle_axes (basexlim , baseylim , [bottom , bottom ],
3462+ orientation )
3463+ self .auto_scale_xyz ([* jx , * xlim ], [* jy , * ylim ], [* jz , * zlim ], had_data )
3464+
3465+ return stem_container
3466+
3467+ stem3D = stem
3468+
33543469docstring .interpd .update (Axes3D_kwdoc = artist .kwdoc (Axes3D ))
33553470docstring .dedent_interpd (Axes3D .__init__ )
33563471
0 commit comments