When to Use
- Density functions: Visualize Gaussian peaks, kernel density estimates
- Spatial expression: Show gene expression gradients across tissue
- Topographic maps: Display elevation contours
- Probability distributions: Visualize bivariate distributions
- Simulation results: Show temperature, pressure, or concentration fields
- Any continuous 2D field: When data varies smoothly across space
Basic Example
Input Modes
with_grid(z, x_coords, y_coords)
Supply data as a pre-computed regular grid.
- z —
Vec<Vec<f64>>wherez[row][col]is the scalar value at(x_coords[col], y_coords[row]) - x_coords / y_coords — coordinate vectors defining grid positions
with_points(pts: impl IntoIterator<Item = (f64, f64, f64)>)
Supply data as scattered (x, y, z) points. Values are interpolated onto an internal 50×50 grid using inverse-distance weighting (IDW).
Key Methods
Iso-levels
with_n_levels(n: usize)
Set the number of evenly spaced iso-levels (default 8). Levels are distributed within the z data range, excluding min and max.
with_levels(levels: &[f64])
Set explicit iso-level values. Overrides n_levels.
Line vs Filled Mode
with_filled()
Enable filled mode: fill the area between adjacent iso-levels with colormap colors.
with_legend in filled mode also renders a colorbar.
Line mode (default)
By default, only iso-lines are drawn. Usewith_line_color and with_line_width to customize.
Styling
with_colormap(map: ColorMap)
Set the color map for iso-line or filled-band colors (default Viridis).
with_line_color(color: impl Into<String>)
Set a fixed color for all iso-lines. Has no effect on filled bands.
with_line_width(w: f64)
Set the iso-line stroke width in pixels (default 1.0).
with_legend(label: impl Into<String>)
In filled mode, triggers a colorbar. In line mode, adds a line entry to the legend box.
Examples
Iso-line Contours — Gaussian Peak
Filled Contours — Bimodal Surface
Scattered Input — IDW Interpolation
Explicit Iso-levels
See Also
- Histogram2D — For binned density visualization
- Heatmap — For discrete categorical grids