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:

Implementations§
Source§impl Plot
impl Plot
Sourcepub fn add_plot(&mut self, plot: Box<dyn DrawView>) -> &mut Self
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}");
Sourcepub fn set_domain(&mut self, domain: Domain) -> &mut Self
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.
Sourcepub fn set_codomain(&mut self, codomain: Domain) -> &mut Self
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.
Sourcepub fn set_x_label(&mut self, label: &str) -> &mut Self
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.
Sourcepub fn set_y_label(&mut self, label: &str) -> &mut Self
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.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more