Struct Plot

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

A container used for adding plots.

§Examples

use termplot::*;

let mut plot = Plot::default();
plot.set_domain(Domain(-10.0..10.0))
    .set_codomain(Domain(-0.3..1.2))
    .set_title("Graph title")
    .set_x_label("X axis")
    .set_y_label("Y axis")
    .set_size(Size::new(50, 25))
    .add_plot(Box::new(plot::Graph::new(|x| x.sin() / x)));

println!("{plot}");

Output:

Simple example (plotting)

Implementations§

Source§

impl Plot

Source

pub fn add_plot(&mut self, plot: Box<dyn DrawView>) -> &mut Self

Add a plot or graph to the view.

Multiple types of plots and graphs are already implemented. See plot for all the types of available plots and graphs.

To create a new type of plot, see DrawView.

§Examples
use termplot::{Plot, plot};

let mut plot = Plot::default();
plot.add_plot(Box::new(plot::Graph::new(|x| x.sin() / x)));

println!("{plot}");
Source

pub fn set_domain(&mut self, domain: Domain) -> &mut Self

Set the domain (range of the x axis) of the plot.

By default the domain is from -10 to 10.

This function sets the minimum and maximum x values in the graph.

Source

pub fn set_codomain(&mut self, codomain: Domain) -> &mut Self

Set the codomain (range of the y axis) of the plot.

By default the codomain is from -10 to 10.

This function sets the minimum and maximum y values in the graph.

Source

pub fn set_title(&mut self, title: &str) -> &mut Self

Set the title of the plot.

Source

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

Set the label of the x axis.

The label is shown at the bottom of the figure.

Source

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

Set the label of the y axis.

The label is shown at the bottom of the figure.

Source

pub fn set_size(&mut self, size: Size) -> &mut Self

Set the size of the view. This does not include decorations around the plot.

The size is not the number of chars but the number of pixels. Pixels are smaller than chars. A char in the terminal is 2 by 4 pixels.

Trait Implementations§

Source§

impl Default for Plot

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Plot

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.