Plot guides › Chart types

Heatmap

A heatmap colours each cell of a matrix by its value, so patterns across two categorical axes (weekday × hour, gene × sample) stand out without reading every number.

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

When to use it

Watch out: Use a perceptually uniform colormap such as viridis; rainbow maps create false boundaries.

Ask for it in pltchat

Upload your file and type something like:

"heatmap of average orders by weekday and hour, annotate the cells"

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 pandas as pd
import matplotlib.pyplot as plt

rng = np.random.default_rng(12)
days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
hours = [f"{h}:00" for h in range(8, 20, 2)]
base = np.outer([1, 1, 1.1, 1.1, 1.3, 1.6, 1.4], [0.5, 1, 1.4, 1.2, 1.5, 1.1])
df = pd.DataFrame((base * 20 + rng.normal(0, 2, base.shape)).round(),
                  index=days, columns=hours)

fig, ax = plt.subplots(figsize=(6.4, 4))
im = ax.imshow(df, cmap="viridis", aspect="auto")
ax.set_xticks(range(len(hours)), hours)
ax.set_yticks(range(len(days)), days)
for i in range(len(days)):
    for j in range(len(hours)):
        v = df.iat[i, j]
        ax.text(j, i, f"{v:.0f}", ha="center", va="center",
                color="w" if v < df.values.mean() else "k", fontsize=8)
fig.colorbar(im, ax=ax, label="Orders")
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