Struct plotpy::Contour

source ·
pub struct Contour { /* private fields */ }
Expand description

Generates a contour plot

§Example

use plotpy::{Contour, Plot, generate3d};

fn main() -> Result<(), &'static str> {
    // generate (x,y,z) matrices
    let n = 21;
    let (x, y, z) = generate3d(-2.0, 2.0, -2.0, 2.0, n, n, |x, y| x * x - y * y);

    // configure contour
    let mut contour = Contour::new();
    contour
        .set_colorbar_label("temperature")
        .set_colormap_name("terrain")
        .set_selected_line_color("#f1eb67")
        .set_selected_line_width(12.0)
        .set_selected_level(0.0, true);

    // draw contour
    contour.draw(&x, &y, &z);

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

    // save figure
    plot.save("/tmp/plotpy/doc_tests/doc_contour.svg")?;
    Ok(())
}

doc_contour.svg

See also integration tests in the tests directory

Output from some integration tests:

integ_contour.svg

Implementations§

source§

impl Contour

source

pub fn new() -> Self

Creates a new Contour object

source

pub fn draw<'a, T, U>(&mut self, x: &'a T, y: &'a T, z: &'a T)
where T: AsMatrix<'a, U>, U: 'a + Display,

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 U of the input matrices must be a number.
source

pub fn set_colors(&mut self, colors: &[&str]) -> &mut Self

Sets the colors to be used instead of a pre-defined colormap

Will use colormap_index instead if its empty.

source

pub fn set_levels(&mut self, levels: &[f64]) -> &mut Self

Sets pre-defined levels, otherwise automatically calculate levels

source

pub fn set_colormap_index(&mut self, index: usize) -> &mut Self

Sets the colormap index

Options:

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

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

Sets the colormap name

Colormap names:

Will use colormap_index instead if colormap_name is empty.

source

pub fn set_no_lines(&mut self, flag: bool) -> &mut Self

Sets option to skip drawing a lines contour on top of the filled contour

source

pub fn set_no_labels(&mut self, flag: bool) -> &mut Self

Sets option to skip adding labels to the lines contour (if enabled)

source

pub fn set_no_inline_labels(&mut self, flag: bool) -> &mut Self

Sets option to skip drawing labels inline with the contour lines (if enabled)

source

pub fn set_no_colorbar(&mut self, flag: bool) -> &mut Self

Sets option to skip drawing a colorbar

source

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

Sets the colorbar label

source

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

Sets the number format for the labels in the colorbar (cb)

source

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

Sets the line color for the lines contour (default is black)

source

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

Sets the line style for the lines contour

Options:

  • -”, “:”, “--”, “-.
source

pub fn set_line_width(&mut self, width: f64) -> &mut Self

Sets the line width for the lines contour

source

pub fn set_fontsize_labels(&mut self, fontsize: f64) -> &mut Self

Sets the font size for labels

source

pub fn set_selected_level(&mut self, level: f64, enabled: bool) -> &mut Self

Sets option to draw a line contour with a selected level (e.g., 0.0)

Will draw the selected level (e.g., 0.0) on top of everything

source

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

Sets the color to mark the selected level

source

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

Sets the line style for the selected level

Options:

  • -”, “:”, “--”, “-.
source

pub fn set_selected_line_width(&mut self, width: f64) -> &mut Self

Sets the line width for the selected level

Trait Implementations§

source§

impl GraphMaker for Contour

source§

fn get_buffer<'a>(&'a self) -> &'a String

Returns the text buffer with Python3 commands
source§

fn clear_buffer(&mut self)

Clear the text buffer with Python commands

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.