Image

Struct Image 

Source
pub struct Image { /* private fields */ }
Expand description

Generates an image plot (imshow)

See Matplotlib’s documentation

§Examples

use plotpy::{Image, Plot, StrError};

fn main() -> Result<(), StrError> {
    // set values
    let data = [
        [0.8, 2.4, 2.5, 3.9, 0.0, 4.0, 0.0],
        [2.4, 0.0, 4.0, 1.0, 2.7, 0.0, 0.0],
        [1.1, 2.4, 0.8, 4.3, 1.9, 4.4, 0.0],
        [0.6, 0.0, 0.3, 0.0, 3.1, 0.0, 0.0],
        [0.7, 1.7, 0.6, 2.6, 2.2, 6.2, 0.0],
        [1.3, 1.2, 0.0, 0.0, 0.0, 3.2, 5.1],
        [0.1, 2.0, 0.0, 1.4, 0.0, 1.9, 6.3],
    ];

    // image plot and options
    let mut img = Image::new();
    img.set_colormap_name("hsv").draw(&data);

    // save figure
    let mut plot = Plot::new();
    plot.add(&img);
    plot.save("/tmp/plotpy/doc_tests/doc_image_1.svg")?;
    Ok(())
}

doc_image_1.svg

See also integration test in the tests directory.

Implementations§

Source§

impl Image

Source

pub fn new() -> Self

Creates a new Image object

Source

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

(imshow) Displays data as an image

§Arguments
  • data - 2D matrix-like data structure

See https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imshow.html

Source

pub fn draw_rgb_or_rgba<T>(&mut self, data: &Vec<Vec<Vec<T>>>)
where T: Display + Num,

(imshow) Displays data as an image with RGB or RGB(A) values

§Arguments
  • data - 3D vector with shape (height, width, 3) for RGB or (height, width, 4) for RGBA The inner-most vector contains the color channels.

See https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imshow.html

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_extra(&mut self, extra: &str) -> &mut Self

Trait Implementations§

Source§

impl GraphMaker for Image

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§

§

impl Freeze for Image

§

impl RefUnwindSafe for Image

§

impl Send for Image

§

impl Sync for Image

§

impl Unpin for Image

§

impl UnwindSafe for Image

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

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.