Struct termplot::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§

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}");

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.

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.

Set the title of the plot.

Set the label of the x axis.

The label is shown at the bottom of the figure.

Set the label of the y axis.

The label is shown at the bottom of the figure.

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§

Returns the “default value” for a type. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.