Minimal call
import random
rng = random.Random(24)
xs = [rng.gauss(0, 1) for _ in range(3000)]
df = {"x": xs, "y": [x * 0.6 + rng.gauss(0, 0.8) for x in xs]}
c = pt.chart(df, aes(x="x", y="y"), xlabel="x", ylabel="y")
c.add_hist2d(bins=25)
Docstring
Rectangular 2-D histogram — point counts in a uniform x/y bin grid.
mpl `hist2d` / ggplot `geom_bin2d` / seaborn bivariate `histplot`. The
axis-aligned cousin of hexbin: same colormap-by-count encoding, but
rectangular bins under explicit binwidth control. Cells with no points
stay transparent (the `geom_bin2d` convention, and it keeps a sparse
scatter readable).
API: c.add_hist2d(aes(x="col", y="col"))
Binning (scalar applies to both axes; an (x, y) pair sets them apart):
bins=30 bin count per axis; an explicit edge sequence, or an
(x_edges, y_edges) pair, pins the edges instead
binwidth= fixed bin width(s) instead of a count
binrange= (lo, hi) span to bin over, or ((xlo, xhi), (ylo, yhi));
points outside are dropped
Color:
cmap='viridis' colormap name for coloring cells by count
vmin=0 colormap domain lower bound
vmax=None colormap domain upper bound (defaults to max count)