stats.Hexbin
Counts the points in each hexagon of a hexagonal grid over x and y.
Static preview; loading the interactive plot
import hmplot as hm
data = {
"x": [1, 1.4, 2, 2.2, 2.5, 2.7, 3, 3.1, 3.5, 4, 4.2, 5],
"y": [2, 2.6, 3, 2.8, 3.2, 3.1, 3, 3.5, 2.9, 4, 3.8, 4.5],
}
with hm.Plot(data=data, height=300, axes2d=True, aspect="equal") as plot:
with hm.stats.Hexbin(x="x", y="y", bins=4):
hm.Prism(x="x", y="y", width="width", depth="depth", rotation="rotation", shape="hexagon",
z0=0, z1=0, fill="count")
plot
Usage
Outputs occupied-cell centers, width, depth, rotation, count, and columns: reduction expressions as in Group (columns={{ mean_v: mean("v") }}). Defaults to 30 cells across X and pointy orientation. radius chooses an explicit cell radius. Facets share the lattice unless sharedBins is false.
The cells are regular hexagons in data units: a Plot that fills its box scales x and y independently and stretches them. Give the Plot aspect="equal" (as the example does) when the cells should look regular, with one data unit as long on x as on y.
To let the viewer change a setting, read an input in it: bins={input("bins")} (Python bins=hm.input.bins), where bins is a Slider.