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.