Hexbin plot
A hexbin plot divides the plane into hexagons and colours each by how many points fall inside, which turns an overplotted scatter of thousands of points into a readable density map.
When to use it
- Tens of thousands of points or more.
- Where most points are matters more than individual outliers.
Ask for it in pltchat
Upload your file and type something like:
"hexbin of pickup longitude vs latitude, log colour scale"
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
rng = np.random.default_rng(26)
n = 100_000
x = np.r_[rng.normal(0, 1, n), rng.normal(2.5, 0.6, n // 3)]
y = np.r_[0.6 * x[:n] + rng.normal(0, 0.8, n), rng.normal(-1, 0.5, n // 3)]
fig, ax = plt.subplots(figsize=(6.4, 4))
hb = ax.hexbin(x, y, gridsize=50, bins="log", cmap="viridis", mincnt=1)
fig.colorbar(hb, ax=ax, label="Count (log)")
ax.set_xlabel("x")
ax.set_ylabel("y")
plt.tight_layout()
plt.show()
Upload a CSV, Excel, JSON or Parquet file. Your first plot is always free.