Struct plotpy::Legend [−][src]
pub struct Legend {
pub fontsize: f64,
pub handle_len: f64,
pub num_col: i32,
pub location: String,
pub outside: bool,
pub show_frame: bool,
pub x_coords_outside: Vec<f64>,
// some fields omitted
}
Expand description
Generates a Legend
Example
// import
use plotpy::*;
use std::path::Path;
// directory to save figures
const OUT_DIR: &str = "/tmp/plotpy/doc_tests";
// generate (x,y) points
let x = &[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0];
let y1 = &[1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5];
let y2 = &[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0];
let y3 = &[1.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0];
let y4 = &[1.0, 4.0, 9.0, 16.0, 25.0, 36.0, 49.0, 64.0];
// 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.label = "first".to_string();
curve2.label = "second".to_string();
curve3.label = "third".to_string();
curve4.label = "fourth".to_string();
curve1.draw(x, y1);
curve2.draw(x, y2);
curve3.draw(x, y3);
curve4.draw(x, y4);
// add curves to plot
let mut plot = Plot::new();
plot.add(&curve1);
plot.add(&curve2);
plot.add(&curve3);
plot.add(&curve4);
// configure and draw legend
let mut legend = Legend::new();
legend.fontsize = 18.0;
legend.handle_len = 5.5;
legend.num_col = 2;
legend.outside = true;
legend.show_frame = false;
legend.draw();
// add legend to plot
plot.add(&legend);
plot.grid_and_labels("x", "y");
// save figure
let path = Path::new(OUT_DIR).join("doc_legend.svg");
plot.save(&path)?;
Fields
fontsize: f64
Fontsize
handle_len: f64
Length of legend’s indicator line
num_col: i32
Number of columns
location: String
Location, e.g., “best”, “right”, “center left”
Only used if outside == false
outside: bool
Put legend outside plot area
show_frame: bool
Show frame around legend
x_coords_outside: Vec<f64>
Normalized coordinates to put legend outsize