Skip to main content

ContourArtist

Struct ContourArtist 

Source
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: bool

Whether to fill regions between levels (true for contourf).

§cmap: Colormap

Colormap used to map contour levels to colors.

§colors: Option<Vec<Color>>

Optional explicit colors for each contour level, overriding the colormap.

§linewidths: f64

Stroke width for contour lines (unfilled mode). Default 1.0.

§label: Option<String>

Optional legend label.

§color: Color

Primary color (used for legend swatch).

§num_levels: usize

Number of auto-computed levels when levels is None. Default 10.

Implementations§

Source§

impl ContourArtist

Source

pub fn data_bounds(&self) -> (f64, f64, f64, f64)

Computes the data-space bounding box (xmin, xmax, ymin, ymax).

Returns the extent of the x and y grid coordinates. Falls back to (0.0, 1.0, 0.0, 1.0) when either coordinate vector is empty.

Source§

impl ContourArtist

Source

pub fn colormap(&mut self, cmap: Colormap) -> &mut Self

Sets the colormap used to map contour levels to colors.

Source

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.

Source

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.

Source

pub fn linewidths(&mut self, w: f64) -> &mut Self

Sets the line width for contour lines (unfilled mode).

Source

pub fn colors(&mut self, colors: Vec<Color>) -> &mut Self

Sets explicit colors for contour levels, overriding the colormap.

Source

pub fn label(&mut self, label: &str) -> &mut Self

Sets the legend label.

Source

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.

Source

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.

Source

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).

Source

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

Source§

fn clone(&self) -> ContourArtist

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ContourArtist

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.