Kernel density estimation for contour generation from point data.
Estimates a continuous density surface from scattered points using Gaussian kernel density estimation, then generates contours from the resulting grid.
Examples
# Generate density contours from points
points = [
%{x: 10, y: 20},
%{x: 15, y: 25},
%{x: 12, y: 22},
# ... more points
]
density = Visualize.Contour.Density.new()
|> Visualize.Contour.Density.x(fn d -> d.x end)
|> Visualize.Contour.Density.y(fn d -> d.y end)
|> Visualize.Contour.Density.size(100, 100)
|> Visualize.Contour.Density.bandwidth(10)
|> Visualize.Contour.Density.thresholds(10)
contours = Visualize.Contour.Density.compute(density, points)Algorithm
Uses Gaussian kernel density estimation:
- For each grid cell, sum the weighted contributions from all points
- Weight is based on distance using Gaussian kernel: K(u) = exp(-u²/2)
- Bandwidth controls the smoothness (larger = smoother)
Summary
Functions
Sets the bandwidth (kernel size) for density estimation.
Sets the cell size for the density grid
Computes density contours from point data.
Creates a new density estimator
Renders density contours as SVG paths.
Sets the output dimensions
Sets the threshold values for contour generation.
Sets the weight accessor function
Sets the x accessor function
Sets the y accessor function
Types
@type t() :: %Visualize.Contour.Density{ bandwidth: number(), cell_size: pos_integer(), height: pos_integer(), thresholds: [number()] | pos_integer(), weight: (any() -> number()) | nil, width: pos_integer(), x: (any() -> number()) | nil, y: (any() -> number()) | nil }
Functions
Sets the bandwidth (kernel size) for density estimation.
Larger values produce smoother results but may obscure detail.
@spec cell_size(t(), pos_integer()) :: t()
Sets the cell size for the density grid
@spec compute(t(), Visualize.Data.Table.source()) :: [ Visualize.Contour.contour_result() ]
Computes density contours from point data.
Returns a list of contour objects compatible with Visualize.Contour.
@spec new() :: t()
Creates a new density estimator
Renders density contours as SVG paths.
@spec size(t(), pos_integer(), pos_integer()) :: t()
Sets the output dimensions
@spec thresholds(t(), [number()] | pos_integer()) :: t()
Sets the threshold values for contour generation.
Can be a list of specific values or a count (generates that many levels).
Sets the weight accessor function
Sets the x accessor function
Sets the y accessor function