pub struct Legend { /* private fields */ }Expand description
Generates a Legend
Example
use plotpy::{Curve, Legend, Plot, StrError};
use russell_lab::Vector;
fn main() -> Result<(), StrError> {
// generate (x,y) points
let x = Vector::linspace(0.0, 5.0, 6)?;
let y1 = x.get_mapped(|v| 0.5 * v);
let y2 = x.get_mapped(|v| 1.0 * v);
let y3 = x.get_mapped(|v| 1.5 * v);
let y4 = x.get_mapped(|v| 2.0 * v);
// configure and draw curves
let mut curve1 = Curve::new();
let mut curve2 = Curve::new();
let mut curve3 = Curve::new();
let mut curve4 = Curve::new();
curve1.set_label("y = 0.5 x");
curve2.set_label("y = 1.0 x");
curve3.set_label("y = 1.5 x");
curve4.set_label("y = 2.0 x");
curve1.draw(&x, &y1);
curve2.draw(&x, &y2);
curve3.draw(&x, &y3);
curve4.draw(&x, &y4);
// configure and draw legends
let mut legend1 = Legend::new();
legend1.set_fontsize(14.0)
.set_handle_len(6.0)
.set_num_col(2)
.set_outside(true)
.set_show_frame(false);
legend1.draw();
let mut legend2 = Legend::new();
legend2.draw();
// add curves and legends to subplots
let mut plot = Plot::new();
plot.set_subplot(2, 1, 1)
.add(&curve1)
.add(&curve2)
.add(&curve3)
.add(&curve4)
.add(&legend1);
plot.set_subplot(2, 1, 2)
.add(&curve1)
.add(&curve2)
.add(&curve3)
.add(&curve4)
.add(&legend2);
// save figure
plot.save("/tmp/plotpy/doc_tests/doc_legend.svg")?;
Ok(())
}See also integration tests in the tests directory
Implementations
sourceimpl Legend
impl Legend
sourcepub fn set_fontsize(&mut self, fontsize: f64) -> &mut Self
pub fn set_fontsize(&mut self, fontsize: f64) -> &mut Self
Sets the fontsize
sourcepub fn set_handle_len(&mut self, length: f64) -> &mut Self
pub fn set_handle_len(&mut self, length: f64) -> &mut Self
Sets the length of legend’s indicator line
sourcepub fn set_num_col(&mut self, num_columns: usize) -> &mut Self
pub fn set_num_col(&mut self, num_columns: usize) -> &mut Self
Sets the number of columns
sourcepub fn set_location(&mut self, location: &str) -> &mut Self
pub fn set_location(&mut self, location: &str) -> &mut Self
Sets the location
Options:
- “best”, “right”, “center left”
- Note: Only used if outside == false
sourcepub fn set_outside(&mut self, flag: bool) -> &mut Self
pub fn set_outside(&mut self, flag: bool) -> &mut Self
Sets option to put legend outside of plot area
sourcepub fn set_show_frame(&mut self, flag: bool) -> &mut Self
pub fn set_show_frame(&mut self, flag: bool) -> &mut Self
Sets option to show frame around legend
sourcepub fn set_x_coords(&mut self, coords: &[f64]) -> &mut Self
pub fn set_x_coords(&mut self, coords: &[f64]) -> &mut Self
Sets the normalized coordinates when drawing an outside legend
Example: [0.0, 1.02, 1.0, 0.102]
Trait Implementations
sourceimpl GraphMaker for Legend
impl GraphMaker for Legend
fn get_buffer<'a>(&'a self) -> &'a String
Auto Trait Implementations
impl RefUnwindSafe for Legend
impl Send for Legend
impl Sync for Legend
impl Unpin for Legend
impl UnwindSafe for Legend
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more