3D surface plot
A 3D surface plot renders a function of two variables as a shaded surface. It looks impressive and gives an intuitive shape, but exact values are hard to read off.
When to use it
- You want an intuitive picture of a surface's overall shape.
- A slide or a teaching figure, rather than a precise reading.
Watch out: Perspective hides parts of the surface and distorts values. For papers, a contour plot or heatmap is usually clearer.
Ask for it in pltchat
Upload your file and type something like:
"3D surface of z over x and y with a colormap"
pltchat writes the loader and the plot for your columns, runs it in your browser and shows you the code.
The matplotlib code
Self-contained with example data; swap in pd.read_csv(...) or
pd.read_excel(...) for your own file.
import numpy as np
import matplotlib.pyplot as plt
x = y = np.linspace(-3, 3, 80)
X, Y = np.meshgrid(x, y)
Z = np.sin(X) * np.cos(Y) * np.exp(-(X**2 + Y**2) / 8)
fig = plt.figure(figsize=(6.4, 4.5))
ax = fig.add_subplot(projection="3d")
surf = ax.plot_surface(X, Y, Z, cmap="viridis", linewidth=0, antialiased=True)
fig.colorbar(surf, ax=ax, shrink=0.6, label="z")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.view_init(elev=30, azim=-60)
plt.tight_layout()
plt.show()
Upload a CSV, Excel, JSON or Parquet file. Your first plot is always free.