Plot guides › Chart types

Contour plot

A contour plot draws lines (or filled bands) of equal value across a 2D surface, like a topographic map. It shows a function of two variables without the distortion of a 3D view.

Example contour plot made with matplotlib
Rendered from the code below, with example data.

When to use it

Ask for it in pltchat

Upload your file and type something like:

"filled contour plot of yield over temperature and pH, label the contour lines"

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

temp = np.linspace(20, 60, 120)
ph = np.linspace(4, 9, 120)
T, P = np.meshgrid(temp, ph)
yield_ = 90 * np.exp(-((T - 42) / 10) ** 2 - ((P - 6.8) / 1.3) ** 2)

fig, ax = plt.subplots(figsize=(6.4, 4))
cf = ax.contourf(T, P, yield_, levels=12, cmap="viridis")
cs = ax.contour(T, P, yield_, levels=[20, 40, 60, 80], colors="w", linewidths=0.8)
ax.clabel(cs, fmt="%d%%", fontsize=8)
fig.colorbar(cf, ax=ax, label="Yield (%)")
ax.set_xlabel("Temperature (°C)")
ax.set_ylabel("pH")
plt.tight_layout()
plt.show()

Make this with your data

Upload a CSV, Excel, JSON or Parquet file. Your first plot is always free.

Related plots