When to Use
- Gene expression: Show expression levels across samples/conditions
- Correlation matrices: Visualize pairwise correlations between variables
- Confusion matrices: Display classification performance
- Distance/similarity matrices: Reveal clustering structure
- Contingency tables: Show counts across categorical dimensions
- Any matrix data: When rows and columns have categorical labels
Basic Example
Key Methods
with_data(data)
Set the grid data as a nested iterable. Outer iterator produces rows (top to bottom); inner iterator produces columns (left to right).
Into<f64>.
with_labels(rows: Vec<String>, cols: Vec<String>)
Store row and column label strings in the struct. Important: These are not rendered automatically. To display them on the axes, pass them separately to Layout:
with_color_map(map: ColorMap)
Set the color map applied after normalizing values to [0.0, 1.0]. Options:
ColorMap::Viridis(default) — Blue → green → yellow; perceptually uniformColorMap::Inferno— Black → purple → yellow; high contrastColorMap::Grayscale— Black → white; print-friendlyColorMap::Custom(Arc<dyn Fn(f64) -> String>)— User-defined mapping
with_values()
Overlay numeric values inside each cell, formatted to two decimal places.
with_legend(label: impl Into<String>)
Attach a legend label to the heatmap.
Examples
Minimal Heatmap
Gene Expression Heatmap
Value Overlay
Colormap Comparison
Colorbar
A colorbar is always shown in the right margin, mapping the data range to the active color map.See Also
- Histogram2D — For binned scatter data instead of pre-computed grids
- DotPlot — For encoding two variables (size and color) in a categorical grid