Skip to content

Commit f25fe90

Browse files
committed
DOC: Add what's new for stem3d, and tweak example.
1 parent d6da94c commit f25fe90

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

doc/users/next_whats_new/stem3d.rst

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Stem plots in 3D Axes
2+
---------------------
3+
4+
Stem plots are now supported on 3D Axes. Much like 2D stems,
5+
`~.axes3d.Axes3D.stem3D` supports plotting the stems in various orientations:
6+
7+
.. plot::
8+
9+
theta = np.linspace(0, 2*np.pi)
10+
x = np.cos(theta - np.pi/2)
11+
y = np.sin(theta - np.pi/2)
12+
z = theta
13+
directions = ['z', 'x', 'y']
14+
names = [r'$\theta$', r'$\cos\theta$', r'$\sin\theta$']
15+
16+
fig, axs = plt.subplots(1, 3, figsize=(8, 4),
17+
constrained_layout=True,
18+
subplot_kw={'projection': '3d'})
19+
for ax, zdir, name in zip(axs, directions, names):
20+
ax.stem(x, y, z, orientation=zdir)
21+
ax.set_title(name)
22+
fig.suptitle(r'A parametric circle: $(x, y) = (\cos\theta, \sin\theta)$')
23+
24+
See also the :doc:`/gallery/mplot3d/stem3d_demo` demo.

examples/mplot3d/stem3d_demo.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import numpy as np
1212

1313
theta = np.linspace(0, 2*np.pi)
14-
x = np.cos(theta)
15-
y = np.sin(theta)
14+
x = np.cos(theta - np.pi/2)
15+
y = np.sin(theta - np.pi/2)
1616
z = theta
1717

1818
fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))
@@ -34,3 +34,18 @@
3434
markerline.set_markerfacecolor('none')
3535

3636
plt.show()
37+
38+
#############################################################################
39+
#
40+
# The orientation of the stems and baseline can be changed using *orientation*.
41+
# This determines in which direction the stems are projected from the head
42+
# points, towards the *bottom* baseline.
43+
#
44+
# For examples, by setting ``orientation='x'``, the stems are projected along
45+
# the *x*-direction, and the baseline is in the *yz*-plane.
46+
47+
fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))
48+
markerline, stemlines, baseline = ax.stem(x, y, z, bottom=-1, orientation='x')
49+
ax.set(xlabel='x', ylabel='y', zlabel='z')
50+
51+
plt.show()

0 commit comments

Comments
 (0)