Note
Go to the end to download the full example code.
3D Plotting#
Demonstrate the three 3-D geometry types supported by
plot_surface(),
scatter3d(), and
plot3d().
Drag to rotate, scroll to zoom, press R to reset the view.
import numpy as np
import anyplotlib as vw
# ── Surface ───────────────────────────────────────────────────────────────────
x = np.linspace(-3, 3, 60)
y = np.linspace(-3, 3, 60)
XX, YY = np.meshgrid(x, y)
ZZ = np.sin(np.sqrt(XX ** 2 + YY ** 2))
fig, ax = vw.subplots(1, 1, figsize=(520, 480))
surf = ax.plot_surface(XX, YY, ZZ,
colormap="viridis",
x_label="x", y_label="y", z_label="sin(r)")
fig
Scatter plot#
rng = np.random.default_rng(1)
n = 300
theta = rng.uniform(0, 2 * np.pi, n)
phi = rng.uniform(0, np.pi, n)
r = rng.uniform(0.6, 1.0, n)
xs = r * np.sin(phi) * np.cos(theta)
ys = r * np.sin(phi) * np.sin(theta)
zs = r * np.cos(phi)
fig2, ax2 = vw.subplots(1, 1, figsize=(480, 480))
sc = ax2.scatter3d(xs, ys, zs,
color="#4fc3f7", point_size=3,
x_label="x", y_label="y", z_label="z")
fig2
3-D line — parametric helix#
Update the surface data live#
Call update() to replace the geometry
without recreating the panel.
Total running time of the script: (0 minutes 0.469 seconds)