Box plot
A box plot summarises a distribution in five numbers: the box spans the 25th to 75th percentile, the line inside is the median, whiskers reach to 1.5 × IQR, and points beyond are drawn as outliers.
When to use it
- You compare distributions across several groups side by side.
- You want a compact summary that is robust to outliers.
Watch out: A box hides bimodality and the sample size. With few points, overlay the raw data.
Ask for it in pltchat
Upload your file and type something like:
"box plot of length per species"
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(9)
df = pd.DataFrame([{"species": s, "length": rng.normal(mu, sd)}
for s, mu, sd in [("setosa", 5.0, 0.35), ("versicolor", 5.9, 0.5),
("virginica", 6.6, 0.6)]
for _ in range(50)])
groups = [g["length"].to_numpy() for _, g in df.groupby("species")]
labels = sorted(df["species"].unique())
fig, ax = plt.subplots(figsize=(6.4, 4))
ax.boxplot(groups, tick_labels=labels, widths=0.5)
ax.set_ylabel("Sepal length (cm)")
ax.spines[["top", "right"]].set_visible(False)
plt.tight_layout()
plt.show()
Upload a CSV, Excel, JSON or Parquet file. Your first plot is always free.