Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7985c21

Browse files
committed
DOC: Add 3D plots to plot_types gallery
1 parent 4965500 commit 7985c21

File tree

7 files changed

+154
-0
lines changed

7 files changed

+154
-0
lines changed

doc/sphinxext/gallery_order.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
'../plot_types/arrays',
2929
'../plot_types/stats',
3030
'../plot_types/unstructured',
31+
'../plot_types/3D',
3132
]
3233

3334

plot_types/3D/README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. _3D_plots:
2+
3+
3D
4+
--
5+
6+
3D plots using the `mpl_toolkits.mplot3d` library.

plot_types/3D/scatter3d_simple.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
==============
3+
3D scatterplot
4+
==============
5+
6+
See `~mpl_toolkits.mplot3d.axes3d.Axes3D.scatter`.
7+
"""
8+
import matplotlib.pyplot as plt
9+
import numpy as np
10+
11+
plt.style.use('_mpl-gallery')
12+
13+
# Make data
14+
np.random.seed(19680801)
15+
n = 100
16+
rng = np.random.default_rng()
17+
xs = rng.uniform(23, 32, n)
18+
ys = rng.uniform(0, 100, n)
19+
zs = rng.uniform(-50, -25, n)
20+
21+
# Plot
22+
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
23+
ax.scatter(xs, ys, zs)
24+
25+
ax.set(xticklabels=[],
26+
yticklabels=[],
27+
zticklabels=[])
28+
29+
plt.show()

plot_types/3D/surface3d_simple.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
=====================
3+
3D surface
4+
=====================
5+
6+
See `~mpl_toolkits.mplot3d.axes3d.Axes3D.plot_surface`.
7+
"""
8+
import matplotlib.pyplot as plt
9+
from matplotlib import cm
10+
import numpy as np
11+
12+
plt.style.use('_mpl-gallery')
13+
14+
# Make data
15+
X = np.arange(-5, 5, 0.25)
16+
Y = np.arange(-5, 5, 0.25)
17+
X, Y = np.meshgrid(X, Y)
18+
R = np.sqrt(X**2 + Y**2)
19+
Z = np.sin(R)
20+
21+
# Plot the surface
22+
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
23+
ax.plot_surface(X, Y, Z, vmin=Z.min() * 2, cmap=cm.Blues)
24+
25+
ax.set(xticklabels=[],
26+
yticklabels=[],
27+
zticklabels=[])
28+
29+
plt.show()

plot_types/3D/trisurf3d_simple.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
======================
3+
Triangular 3D surfaces
4+
======================
5+
6+
See `~mpl_toolkits.mplot3d.axes3d.Axes3D.plot_trisurf`.
7+
"""
8+
import matplotlib.pyplot as plt
9+
from matplotlib import cm
10+
import numpy as np
11+
12+
plt.style.use('_mpl-gallery')
13+
14+
n_radii = 8
15+
n_angles = 36
16+
17+
# Make radii and angles spaces
18+
radii = np.linspace(0.125, 1.0, n_radii)
19+
angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)[..., np.newaxis]
20+
21+
# Convert polar (radii, angles) coords to cartesian (x, y) coords.
22+
x = np.append(0, (radii*np.cos(angles)).flatten())
23+
y = np.append(0, (radii*np.sin(angles)).flatten())
24+
z = np.sin(-x*y)
25+
26+
# Plot
27+
fig, ax = plt.subplots(subplot_kw={'projection': '3d'})
28+
ax.plot_trisurf(x, y, z, vmin=z.min() * 2, cmap=cm.Blues)
29+
30+
ax.set(xticklabels=[],
31+
yticklabels=[],
32+
zticklabels=[])
33+
34+
plt.show()

plot_types/3D/voxels_simple.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
==========================
3+
3D voxel / volumetric plot
4+
==========================
5+
6+
See `~mpl_toolkits.mplot3d.axes3d.Axes3D.voxels`.
7+
"""
8+
import matplotlib.pyplot as plt
9+
import numpy as np
10+
11+
plt.style.use('_mpl-gallery')
12+
13+
# Prepare some coordinates
14+
x, y, z = np.indices((8, 8, 8))
15+
16+
# Draw cuboids in the top left and bottom right corners
17+
cube1 = (x < 3) & (y < 3) & (z < 3)
18+
cube2 = (x >= 5) & (y >= 5) & (z >= 5)
19+
20+
# Combine the objects into a single boolean array
21+
voxelarray = cube1 | cube2
22+
23+
# Plot
24+
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
25+
ax.voxels(voxelarray, edgecolor='k')
26+
27+
ax.set(xticklabels=[],
28+
yticklabels=[],
29+
zticklabels=[])
30+
31+
plt.show()

plot_types/3D/wire3d_simple.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
=================
3+
3D wireframe plot
4+
=================
5+
6+
See `~mpl_toolkits.mplot3d.axes3d.Axes3D.plot_wireframe`.
7+
"""
8+
from mpl_toolkits.mplot3d import axes3d
9+
import matplotlib.pyplot as plt
10+
11+
plt.style.use('_mpl-gallery')
12+
13+
# Make data
14+
X, Y, Z = axes3d.get_test_data(0.05)
15+
16+
# Plot
17+
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
18+
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)
19+
20+
ax.set(xticklabels=[],
21+
yticklabels=[],
22+
zticklabels=[])
23+
24+
plt.show()

0 commit comments

Comments
 (0)