Skip to main content

Canvas

Struct Canvas 

Source
pub struct Canvas {
    pub axes: Axes,
    pub image: Image,
    /* private fields */
}
Expand description

An image-backed plotting surface.

Canvas keeps the rendered image, the current axis configuration, and any series added to it. It is the lower-level incremental API for custom plotting workflows while Plot provides a simpler higher-level builder interface.

Fields§

§axes: Axes

The current axis configuration used to map data coordinates to pixels.

§image: Image

The rasterized plot image.

Implementations§

Source§

impl Canvas

Source

pub fn new(width: usize, height: usize, axes: Axes) -> Self

Creates a new canvas with a given pixel size and axis configuration.

Source

pub fn with_inset( width: usize, height: usize, axes: Axes, inset_x: usize, inset_y: usize, ) -> Self

Creates a new canvas with a custom inset margin around the drawing bounds.

Source

pub fn width(&self) -> usize

Returns the canvas width in pixels.

Source

pub fn height(&self) -> usize

Returns the canvas height in pixels.

Source

pub fn insets(&self) -> (usize, usize)

Returns the horizontal and vertical inset values in pixels.

Source

pub fn set_inset(&mut self, inset_x: usize, inset_y: usize)

Updates the inset margins used by the plot area.

Source

pub fn set_render_scale(&mut self, scale: usize)

Sets the render scale used for higher-resolution output.

Source

pub fn render(&mut self)

Draws the axes, labels, and ticks using the current axes configuration.

Source

pub fn scatter(&mut self, points: &[(f64, f64)], size: usize)

Adds a scatter series with a default marker style and explicit marker size.

Source

pub fn markers(&mut self, points: &[(f64, f64)], style: MarkerStyle)

Adds a marker-based series using a custom marker style.

Source

pub fn plot(&mut self, points: &[(f64, f64)], line_width: usize)

Adds a line series with a default width.

Source

pub fn line(&mut self, points: &[(f64, f64)], style: LineStyle)

Adds a line series using a custom style.

Source

pub fn set_xlim(&mut self, xlim: (f64, f64))

Sets the x-axis limits and redraws the canvas.

Source

pub fn set_ylim(&mut self, ylim: (f64, f64))

Sets the y-axis limits and redraws the canvas.

Source

pub fn use_auto_xlim(&mut self)

Re-enables automatic x-axis scaling for data-driven limits.

Source

pub fn use_auto_ylim(&mut self)

Re-enables automatic y-axis scaling for data-driven limits.

Source

pub fn into_image(self) -> Image

Consumes the canvas and returns the rendered image.

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

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.