Skip to content

Commit 0dd0742

Browse files
committed
Modernize stem3d documentation.
1 parent c0af471 commit 0dd0742

File tree

3 files changed

+78
-34
lines changed

3 files changed

+78
-34
lines changed

examples/mplot3d/stem3d_demo.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,36 @@
1-
from mpl_toolkits.mplot3d import Axes3D
1+
"""
2+
=======
3+
3D stem
4+
=======
5+
6+
Demonstration of a stem plot in 3D, which plots vertical lines from a baseline
7+
to the *z*-coordinate and places a marker at the tip.
8+
"""
9+
210
import matplotlib.pyplot as plt
311
import numpy as np
412

5-
fig = plt.figure()
6-
ax = fig.gca(projection='3d')
713
theta = np.linspace(0, 2*np.pi)
814
x = np.cos(theta)
915
y = np.sin(theta)
1016
z = theta
11-
markerline, stemlines, baseline = ax.stem(x, y, z)
17+
18+
fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))
19+
ax.stem(x, y, z)
20+
21+
plt.show()
22+
23+
#############################################################################
24+
#
25+
# The position of the baseline can be adapted using *bottom*. The parameters
26+
# *linefmt*, *markerfmt*, and *basefmt* control basic format properties of the
27+
# plot. However, in contrast to `~.axes3d.Axes3D.plot` not all properties are
28+
# configurable via keyword arguments. For more advanced control adapt the line
29+
# objects returned by `~.stem3D`.
30+
31+
fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))
32+
markerline, stemlines, baseline = ax.stem(
33+
x, y, z, linefmt='grey', markerfmt='D', bottom=np.pi)
34+
markerline.set_markerfacecolor('none')
1235

1336
plt.show()

examples/mplot3d/stem3d_demo2.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3293,26 +3293,61 @@ def stem(self, x, y, z, *, linefmt='C0-', markerfmt='C0o', basefmt='C3-',
32933293
"""
32943294
Create a 3D stem plot.
32953295
3296-
By default, stem plots vertical lines (using *linefmt*) in the z
3297-
direction at each *x* and *y* location from the baseline to *z*, and
3298-
places a marker there using *markerfmt*. By default, the baseline at
3299-
the xy-plane is plotted using *basefmt*.
3296+
A stem plot draws lines perpendicular to a baseline, and places markers
3297+
at the heads. By default, the baseline is defined by *x* and *y*, and
3298+
stems are drawn vertically from *bottom* to *z*.
33003299
3301-
*x*, *y, and *z* values are required and must be arrays of the same
3302-
length.
3303-
3304-
If no zdir value is provided, then it is set to default and no rotation
3305-
occurs.
3300+
Parameters
3301+
----------
3302+
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*
3306+
positions are used for the baseline and *z* for the head position,
3307+
but this can be changed by *zdir*.
3308+
3309+
linefmt : str, default: 'C0-'
3310+
A string defining the properties of the vertical lines. Usually,
3311+
this will be a color or a color and a linestyle:
3312+
3313+
========= =============
3314+
Character Line Style
3315+
========= =============
3316+
``'-'`` solid line
3317+
``'--'`` dashed line
3318+
``'-.'`` dash-dot line
3319+
``':'`` dotted line
3320+
========= =============
3321+
3322+
Note: While it is technically possible to specify valid formats
3323+
other than color or color and linestyle (e.g. 'rx' or '-.'), this
3324+
is beyond the intention of the method and will most likely not
3325+
result in a reasonable plot.
3326+
3327+
markerfmt : str, default: 'C0o'
3328+
A string defining the properties of the markers at the stem heads.
3329+
3330+
basefmt : str, default: 'C3-'
3331+
A format string defining the properties of the baseline.
3332+
3333+
bottom : float, default: 0
3334+
The x/y/z-position of the baseline (depending on *zdir*).
3335+
3336+
label : str, default: None
3337+
The label to use for the stems in legends.
33063338
3307-
Return value is a tuple (*markerline*, *stemlines*, *baseline*).
3339+
zdir : {'x', 'y', 'z'}, default: 'z'
3340+
The direction along which stems are drawn.
33083341
3309-
.. seealso::
3310-
This `document
3311-
<http://www.mathworks.com/help/techdoc/ref/stem3.html>`_ for
3312-
details.
3342+
Returns
3343+
-------
3344+
`.StemContainer`
3345+
The container may be treated like a tuple
3346+
(*markerline*, *stemlines*, *baseline*)
33133347
3314-
**Example:**
3315-
.. plot:: /mplot3d/stem3d_demo.py
3348+
Examples
3349+
--------
3350+
.. plot:: gallery/mplot3d/stem3d_demo.py
33163351
"""
33173352

33183353
from matplotlib.container import StemContainer

0 commit comments

Comments
 (0)