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: AxesThe current axis configuration used to map data coordinates to pixels.
image: ImageThe rasterized plot image.
Implementations§
Source§impl Canvas
impl Canvas
Sourcepub fn new(width: usize, height: usize, axes: Axes) -> Self
pub fn new(width: usize, height: usize, axes: Axes) -> Self
Creates a new canvas with a given pixel size and axis configuration.
Sourcepub fn with_inset(
width: usize,
height: usize,
axes: Axes,
inset_x: usize,
inset_y: usize,
) -> Self
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.
Sourcepub fn insets(&self) -> (usize, usize)
pub fn insets(&self) -> (usize, usize)
Returns the horizontal and vertical inset values in pixels.
Sourcepub fn set_inset(&mut self, inset_x: usize, inset_y: usize)
pub fn set_inset(&mut self, inset_x: usize, inset_y: usize)
Updates the inset margins used by the plot area.
Sourcepub fn set_render_scale(&mut self, scale: usize)
pub fn set_render_scale(&mut self, scale: usize)
Sets the render scale used for higher-resolution output.
Sourcepub fn render(&mut self)
pub fn render(&mut self)
Draws the axes, labels, and ticks using the current axes configuration.
Sourcepub fn scatter(&mut self, points: &[(f64, f64)], size: usize)
pub fn scatter(&mut self, points: &[(f64, f64)], size: usize)
Adds a scatter series with a default marker style and explicit marker size.
Sourcepub fn markers(&mut self, points: &[(f64, f64)], style: MarkerStyle)
pub fn markers(&mut self, points: &[(f64, f64)], style: MarkerStyle)
Adds a marker-based series using a custom marker style.
Sourcepub fn plot(&mut self, points: &[(f64, f64)], line_width: usize)
pub fn plot(&mut self, points: &[(f64, f64)], line_width: usize)
Adds a line series with a default width.
Sourcepub fn line(&mut self, points: &[(f64, f64)], style: LineStyle)
pub fn line(&mut self, points: &[(f64, f64)], style: LineStyle)
Adds a line series using a custom style.
Sourcepub fn use_auto_xlim(&mut self)
pub fn use_auto_xlim(&mut self)
Re-enables automatic x-axis scaling for data-driven limits.
Sourcepub fn use_auto_ylim(&mut self)
pub fn use_auto_ylim(&mut self)
Re-enables automatic y-axis scaling for data-driven limits.
Sourcepub fn into_image(self) -> Image
pub fn into_image(self) -> Image
Consumes the canvas and returns the rendered image.