Skip to content

Commit 3eeb45e

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

File tree

7 files changed

+132
-0
lines changed

7 files changed

+132
-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 plot types.

plot_types/3D/scatter3d_simple.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
==============
3+
3D scatterplot
4+
==============
5+
6+
See `~mpl_toolkits.mplot3d.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+
plt.show()

plot_types/3D/surface3d_simple.py

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

plot_types/3D/trisurf3d_simple.py

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

plot_types/3D/voxels_simple.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
==========================
3+
3D voxel / volumetric plot
4+
==========================
5+
6+
See `~mpl_toolkits.mplot3d.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+
plt.show()

plot_types/3D/wire3d_simple.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
=================
3+
3D wireframe plot
4+
=================
5+
6+
See `~mpl_toolkits.mplot3d.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+
plt.show()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy