Struct plotpy::Contour[][src]

pub struct Contour {
Show 19 fields pub colors: Vec<String>, pub levels: Vec<f64>, pub colormap_index: i32, pub colormap_name: String, pub no_lines: bool, pub no_labels: bool, pub no_inline_labels: bool, pub no_colorbar: bool, pub colorbar_label: String, pub colorbar_number_format: String, pub line_color: String, pub line_style: String, pub line_width: f64, pub font_size_labels: f64, pub with_selected: bool, pub selected_level: f64, pub selected_line_color: String, pub selected_line_style: String, pub selected_line_width: f64, // some fields omitted
}
Expand description

Generates a contour plot

Example

// import
use plotpy::*;
use std::path::Path;

// directory to save figures
const OUT_DIR: &str = "/tmp/plotpy/doc_tests";

// generate (x,y,z) matrices
let n = 21;
let mut x = vec![vec![0.0; n]; n];
let mut y = vec![vec![0.0; n]; n];
let mut z = vec![vec![0.0; n]; n];
let (min, max) = (-2.0, 2.0);
let d = (max - min) / ((n - 1) as f64);
for i in 0..n {
    let v = min + (i as f64) * d;
    for j in 0..n {
        let u = min + (j as f64) * d;
        x[i][j] = u;
        y[i][j] = v;
        z[i][j] = u * u - v * v;
    }
}

// configure and draw contour
let mut contour = Contour::new();
contour.colorbar_label = "temperature".to_string();
contour.colormap_name = "terrain".to_string();
contour.with_selected = true;
contour.selected_level = 0.0;
contour.draw(&x, &y, &z);

// add contour to plot
let mut plot = Plot::new();
plot.add(&contour);
plot.labels("x", "y");

// save figure
let path = Path::new(OUT_DIR).join("doc_contour.svg");
plot.save(&path)?;

doc_contour.svg

Fields

colors: Vec<String>

Colors to be used instead of a pre-defined colormap

Will use colormap_index instead if it empty.

levels: Vec<f64>

Pre-defined levels, otherwise automatically calculate levels

colormap_index: i32

Colormap index

  • 0 – bwr
  • 1 – RdBu
  • 2 – hsv
  • 3 – jet
  • 4 – terrain
  • 5 – pink
  • 6 – Greys
  • >6 – starts over from 0
colormap_name: String

Colormap name as defined in https://matplotlib.org/stable/tutorials/colors/colormaps.html

Will use colormap_index instead if colormap_name is empty.

no_lines: bool

Skip drawing a lines contour on top of the filled contour

no_labels: bool

Skip adding labels to the lines contour (if enabled)

no_inline_labels: bool

Do not draw labels inline with the contour lines (if enabled)

no_colorbar: bool

Skip drawing a colorbar

colorbar_label: String

Colorbar label

colorbar_number_format: String

Number format for the labels in lines contour (e.g. “%.2f”)

line_color: String

Line color for the lines contour (default is black)

line_style: String

Line style for the lines contour

Options: “-”, “:”, “--”, “-.

line_width: f64

Line width for the lines contour

font_size_labels: f64

Font size for labels

with_selected: bool

Draw a line contour with a selected level (e.g., 0.0) on top of everything

selected_level: f64

Selected level (e.g., 0.0)

selected_line_color: String

Color to mark the selected level

selected_line_style: String

Line style for the selected level

Options: “-”, “:”, “--”, “-.

selected_line_width: f64

Line width for the selected level

Implementations

Creates a new Contour object

Draws a fancy contour: filled contour with a line contour and a colorbar

Input

  • x – matrix with x values
  • y – matrix with y values
  • z – matrix with z values

Flags

The following flags control what features are not to be drawn:

  • no_lines – skip drawing a lines contour on top of the filled contour
  • no_labels – skip adding labels to the lines contour (if enabled)
  • no_colorbar – skip drawing a colorbar
  • with_selected – draw a line contour with a selected level (e.g., 0.0) on top of everything

Notes

  • The type T of the input matrices must be a number.

Trait Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.