pub struct ContourArtist {
pub x: Vec<f64>,
pub y: Vec<f64>,
pub z: Vec<Vec<f64>>,
pub levels: Option<Vec<f64>>,
pub filled: bool,
pub cmap: Colormap,
pub colors: Option<Vec<Color>>,
pub linewidths: f64,
pub label: Option<String>,
pub color: Color,
pub num_levels: usize,
}Expand description
A contour or filled contour plot over a 2D grid of z = f(x, y) values.
In unfilled mode (filled = false), iso-lines are drawn at each contour
level using the marching squares algorithm. In filled mode (filled = true),
the regions between contour levels are filled with colors from a colormap.
Fields§
§x: Vec<f64>X grid coordinates (length nx).
y: Vec<f64>Y grid coordinates (length ny).
z: Vec<Vec<f64>>Z values on the grid, shape [ny][nx] (row-major).
levels: Option<Vec<f64>>Explicit contour levels. When None, levels are auto-computed.
filled: boolWhether to fill regions between levels (true for contourf).
cmap: ColormapColormap used to map contour levels to colors.
colors: Option<Vec<Color>>Optional explicit colors for each contour level, overriding the colormap.
linewidths: f64Stroke width for contour lines (unfilled mode). Default 1.0.
label: Option<String>Optional legend label.
color: ColorPrimary color (used for legend swatch).
num_levels: usizeNumber of auto-computed levels when levels is None. Default 10.
Implementations§
Source§impl ContourArtist
impl ContourArtist
Source§impl ContourArtist
impl ContourArtist
Sourcepub fn colormap(&mut self, cmap: Colormap) -> &mut Self
pub fn colormap(&mut self, cmap: Colormap) -> &mut Self
Sets the colormap used to map contour levels to colors.
Sourcepub fn levels(&mut self, levels: Vec<f64>) -> &mut Self
pub fn levels(&mut self, levels: Vec<f64>) -> &mut Self
Sets explicit contour levels.
When None, levels are automatically computed by evenly spacing
between the minimum and maximum finite z values.
Sourcepub fn num_levels(&mut self, n: usize) -> &mut Self
pub fn num_levels(&mut self, n: usize) -> &mut Self
Sets the number of automatically computed contour levels.
Only used when explicit levels are not set. Defaults to 10.
Sourcepub fn linewidths(&mut self, w: f64) -> &mut Self
pub fn linewidths(&mut self, w: f64) -> &mut Self
Sets the line width for contour lines (unfilled mode).
Sourcepub fn colors(&mut self, colors: Vec<Color>) -> &mut Self
pub fn colors(&mut self, colors: Vec<Color>) -> &mut Self
Sets explicit colors for contour levels, overriding the colormap.
Sourcepub fn effective_levels(&self) -> Vec<f64>
pub fn effective_levels(&self) -> Vec<f64>
Returns the effective contour levels.
If explicit levels are set, returns those. Otherwise, computes
num_levels evenly spaced levels between the minimum and maximum
finite z values.
Sourcepub fn z_bounds(&self) -> (f64, f64)
pub fn z_bounds(&self) -> (f64, f64)
Returns (zmin, zmax) from the finite z values.
Falls back to (0.0, 1.0) when the data contains no finite values.
Sourcepub fn marching_squares(&self, level: f64) -> Vec<(f64, f64, f64, f64)>
pub fn marching_squares(&self, level: f64) -> Vec<(f64, f64, f64, f64)>
Computes contour line segments for a single level using marching squares.
Returns a list of line segments, each represented as (x0, y0, x1, y1).
Sourcepub fn cell_averages(&self) -> Vec<Vec<f64>>
pub fn cell_averages(&self) -> Vec<Vec<f64>>
Computes the average z value for each grid cell.
Returns a 2D vector of shape [ny-1][nx-1] where each element is the
mean of the four corner z values. Used for the simplified filled
contour approach.
Trait Implementations§
Source§impl Clone for ContourArtist
impl Clone for ContourArtist
Source§fn clone(&self) -> ContourArtist
fn clone(&self) -> ContourArtist
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more