Constructor
new()
Create a contour plot with default settings.
Returns: ContourPlot
Defaults:
- 8 auto-spaced iso-levels
- Viridis colormap
- Line mode (not filled)
- Stroke width 1.0
- No fixed line color
- No legend
Data Input
with_grid()
Supply data as a pre-computed regular grid.
The scalar field as a row-major grid:
z[row][col] where row corresponds to y_coords[row] and col to x_coords[col]X coordinate for each column — must have length equal to
z[0].len()Y coordinate for each row — must have length equal to
z.len()Self
with_points()
Supply data as scattered (x, y, z) points; IDW interpolates to a grid.
Iterator of
(x, y, z) triples at arbitrary positions. The values are interpolated onto an internal 50×50 grid using inverse-distance weighting (IDW) before iso-lines are computed.Self
The input points can be at any positions — they do not need to be on a regular grid. The grid bounds are set to the bounding box of the input points.
Iso-Levels
with_levels()
Set explicit iso-level values.
Slice of explicit iso-level values. When set, these values override
with_n_levels.Self
Use this when iso-lines should correspond to specific thresholds.
with_n_levels()
Set the number of auto-spaced iso-levels.
Number of evenly spaced iso-levels within the z data range (default: 8)
Self
Levels are distributed evenly within the z data range, excluding the minimum and maximum. Ignored when explicit levels are set via with_levels.
Fill Mode
with_filled()
Enable filled mode: fill the area between adjacent iso-levels.
Returns: Self
Each band is colored according to its z value using the active colormap. Calling with_legend in filled mode also renders a colorbar in the right margin.
Styling
with_colormap()
Set the color map used for iso-line or filled-band colors.
Color map applied to iso-levels / filled bands. Options:
ColorMap::Viridis (default), ColorMap::Inferno, ColorMap::Grayscale, or ColorMap::Custom(Arc<Fn>)Self
Default: ColorMap::Viridis
with_line_color()
Set a fixed color for all iso-lines.
CSS color string. When set, all iso-lines are drawn in this color instead of being colored by the colormap.
Self
Has no effect on filled bands — band colors always derive from the colormap.
with_line_width()
Set the iso-line stroke width in pixels.
Stroke width in pixels (default: 1.0)
Self
Legend
with_legend()
Set a legend label.
Legend label text
Self
In filled mode (with_filled) this triggers a colorbar in the right margin using the label as the title. In line mode this adds a line entry to the in-plot legend box.
Utility Methods
effective_levels()
Compute effective iso-levels (respects explicit levels or auto from n_levels).
Returns: Vec<f64>
z_range()
Returns (min, max) of all z values in the grid.
Returns: (f64, f64)
Complete Example
Public Fields
The scalar field as a row-major grid:
z[row][col]X coordinate for each column
Y coordinate for each row
Explicit iso-levels. When non-empty, overrides
n_levelsNumber of auto-spaced iso-levels when
levels is empty (default: 8)When
true, the area between adjacent iso-levels is filled. Default: falseColor map used to assign colors to iso-levels / filled bands. Default:
ColorMap::ViridisIso-line stroke width in pixels (default: 1.0)
Fixed color for all iso-lines.
None = derive from color_mapLegend label