← retour aux snippets

matplotlib: 3D scatter et surface

Créer un scatter 3D et une surface wireframe.

objectif

Créer un scatter 3D et une surface wireframe.

code minimal

from mpl_toolkits.mplot3d import Axes3D  # noqa: F401
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure(); ax = fig.add_subplot(111, projection="3d")
ax.scatter([0,1],[0,1],[0,1])
print("3d ok")

utilisation

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure(); ax = fig.add_subplot(111, projection="3d")
X = np.linspace(-1,1,10); Y = np.linspace(-1,1,10)
X, Y = np.meshgrid(X, Y); Z = X**2 + Y**2
ax.plot_wireframe(X, Y, Z)
print("wire ok")

variante(s) utile(s)

import matplotlib.pyplot as plt
fig = plt.figure(); _ = fig.add_subplot(111, projection="3d"); print("ok")

notes

  • Peut être lent; échantillonner si nécessaire.