Struct Plot

Source
pub struct Plot {
    pub width: i64,
    pub height: i64,
    pub frame: PlotFrame,
    /* private fields */
}
Expand description

Struct used to plot data and generate images.

A plot represents a single drawing area. The region of the image that data is plotted to is refered to as the canvas, which by default, is inset within the full image. The size of the canvas can be changed with with_drawing_bounds.

A plot has two notions of coordinates: “logical” coordinates which are real- valued coordinates that are plotted and “physical” coordinates which are the integer locations of actual pixels. The range of logical coordinates displayed can be changed with with_plotting_range.

Currently data can only be plotted with the low level primitives Circle and Line. This makes plotting somewhat cumbersome, but it also makes this system flexible.

§Examples

Basic sine wave without axis labels

let mut p = Plot::new(300, 200)
  .with_canvas_color(GREY)
  .with_bg_color(BLUE)
  .with_plotting_range(0.0..(2.0 * 3.14), -1.1..1.1)
  .with_drawing_bounds(0.05..0.95, 0.1..0.95);

let x_values: Vec<f64> = (0..1000).map(|i| (i as f64) / 1000.0 * 2.0 * 3.14).collect();
let points: Vec<Point> = x_values.into_iter().map(|x| {
  (x, x.sin()).into()
}).collect();

let circle = Circle::new(RED, 1);
p.draw_circles(&circle, &points);
p.save("sine-wave.bmp").unwrap();

Fields§

§width: i64

The width of the output image.

§height: i64

The width of the output image.

§frame: PlotFrame

Internal only: TODO: Make private

Implementations§

Source§

impl Plot

Source

pub fn new(width: u32, height: u32) -> Plot

Creates a new plot with the given image dimensions.

Source

pub fn clear(&mut self)

Clears all plotted primitives, redrawing the plot frame and canvas.

Source

pub fn draw_line<P>(&mut self, point1: P, point2: P, color: Color)
where P: Into<(f64, f64)>,

Draws a line segment with the given logical coordinate endpoints.

Source

pub fn draw_pixel_line(&mut self, p1: (f64, f64), p2: (f64, f64), color: Color)

Draws a line segment with the given physical pixel endpoints.

Source

pub fn draw_orientations( &mut self, orientation: &Orientation, positions: &[Point], angles: &[f64], )

Plots data as line segments with the given logical positions and angles.

Source

pub fn draw_circles(&mut self, circle: &Circle, positions: &[Point])

Plots data as circles with the given logical positions.

Source

pub fn save(&self, filename: &str) -> Result<(), ImageError>

Saves contents of plot as an image.

Source

pub fn put_pixel_safe(&mut self, x: i64, y: i64, c: Color)

Sets a pixel value, respecting bounds of plotting frame.

Source

pub fn with_drawing_bounds<R: Into<Range<f64>>>( self, x_bounds: R, y_bounds: R, ) -> Self

Changes the fraction of the plot image that the plotting canvas takes up.

This accepts ranges of fractions between 0.0 and 1.0 indicating the portion of the plot that the plottable area takes up. All plotted data is displayed in this area. A bordering frame is drawn around the plotting canvas.

Source

pub fn with_plotting_range<R: Into<Range<f64>>>( self, x_range: R, y_range: R, ) -> Self

Changes the logical coordinate range displayed in the plot.

For example, (0.0, 2.0 * PI), (-1.0, 1.0) would correspond to displaying a single period of a standard sine function.

Source

pub fn with_bg_color(self, color: Color) -> Self

Changes the background color of the plot image (behind the canvas).

Source

pub fn with_canvas_color(self, color: Color) -> Self

Changes the background color of the plotting canvas.

Source

pub fn with_frame_color(self, color: Option<Color>) -> Self

Changes the color of the border around the plotting canvas.

Auto Trait Implementations§

§

impl Freeze for Plot

§

impl RefUnwindSafe for Plot

§

impl Send for Plot

§

impl Sync for Plot

§

impl Unpin for Plot

§

impl UnwindSafe for Plot

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.