Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Hexbin — Hexagonal Density Binning

Signature

sp.hexbin(title, x_values, y_values, *, variant="basic", gridsize=20, colorscale=None, **kwargs) -> Chart

Aliases: sp.hexbin, sp.hexbins, sp.hexbin_chart, sp.hexagonal_binning, sp.build_hexbin

Description

sp.hexbin() bins a 2D scatter cloud into a regular hexagonal grid and colors each hexagon by point density (count), the standard alternative to a scatter plot once point overlap makes individual markers unreadable. Points are assigned to hexagon cells directly in pixel space using the true nearest-center rule (two candidate offset grids, closest wins), so cells tile without gaps or overlap regardless of the data's aspect ratio. Cell color reuses the same continuous colorscale engine as heatmap() and bubble(variant="gradient") — any of viridis / plasma / inferno / magma / cividis / turbo / rdbu / blues / reds / greens works via colorscale=.

Variants

Data

x_values (list[float]) — X coordinates. y_values (list[float]) — Y coordinates.

Parameters

Themes

Returns

Chart — object with .html property and .show() method.

Filled hexagons only, compact grid, right-side density legend.

Variant "basic"Aliases basic / default / classic / filled
Preview

White cell borders; count printed inside each hexagon once cells are large enough to fit text.

Variant "outlined"Aliases outlined / outline / stroke / labeled
Preview

Hexagons drawn at 72% size with a visible gap between neighbors — a "confetti" look instead of a solid tiled surface.

Variant "spaced"Aliases spaced / gapped / confetti
Preview

Dims every cell except the densest ~15% (full opacity, white outline, count label) — draws the eye straight to the hotspots instead of the full density gradient.

Variant "highlight"Aliases highlight / top / hotspot / peak
Preview

Bins below min_count are skipped entirely (left transparent) instead of drawn faint - a hard threshold rather than a dimmed gradient, matching R's hexbin(mincnt=).

Variant "mincnt"Aliases mincnt / threshold / sparse
Preview

Each cell's count is classed into an order-of-magnitude band (ones/tens/hundreds/thousands/10 thousands), colored and sized by band, with a smaller nested hexagon inside in the previous band's color - matching R hexbin's nested/centroid styles - plus a size+color legend.

Variant "nested"Aliases nested / magnitude / rings / centroids
Preview

Cell color is mapped on log(count + 1) instead of the raw count, matching matplotlib's hexbin(bins="log") — compresses the huge dynamic range that skewed point clouds produce so low-density cells stay visually distinguishable instead of collapsing near zero.

Variant "log_counts"Aliases log_counts / log / log_scale / logarithmic
Preview

Cell color encodes the average of a third variable (values=) inside each bin instead of the point count — the native equivalent of matplotlib's hexbin(C=..., reduce_C_function=numpy.mean), for when the quantity of interest isn't density itself.

Variant "weighted"Aliases weighted / mean / aggregate / reduce_mean
Preview

White dashed cell borders over a full continuous colorscale (defaults to magma) with no plot border — matches matplotlib's hexbin(edgecolor="white", linestyle="dotted", linewidth=1.5) styling exactly.

Variant "dotted"Aliases dotted / dashed / styled / magma
Preview

Adds 1D density strips above and to the right of the hexbin grid — a joint-plot style combination, showing the marginal distribution of each axis alongside the 2D density.

Variant "marginals"Aliases marginals / joint / with_histograms / density_marginals
Preview