pub struct Boxplot { /* private fields */ }Expand description
Draw a box and whisker plot
See Matplotlib’s documentation
§Examples
§Data as a nested list
use plotpy::{Boxplot, Plot, StrError};
fn main() -> Result<(), StrError> {
// data (as a nested list)
let data = vec![
vec![1, 2, 3, 4, 5], // A
vec![2, 3, 4, 5, 6, 7, 8, 9, 10], // B
vec![3, 4, 5, 6], // C
vec![4, 5, 6, 7, 8, 9, 10], // D
vec![5, 6, 7], // E
];
// x ticks and labels
let n = data.len();
let ticks: Vec<_> = (1..(n + 1)).into_iter().collect();
let labels = ["A", "B", "C", "D", "E"];
// boxplot object and options
let mut boxes = Boxplot::new();
boxes.draw(&data);
// save figure
let mut plot = Plot::new();
plot.add(&boxes)
.set_title("boxplot documentation test")
.set_ticks_x_labels(&ticks, &labels)
.save("/tmp/plotpy/doc_tests/doc_boxplot_2.svg")?;
Ok(())
}§Data as a 2D array
use plotpy::{Boxplot, Plot, StrError};
fn main() -> Result<(), StrError> {
// data (as a 2D array/matrix)
let data = vec![
// A B C D E
vec![1, 2, 3, 4, 5],
vec![2, 3, 4, 5, 6],
vec![3, 4, 5, 6, 7],
vec![4, 5, 6, 7, 8],
vec![5, 6, 7, 8, 9],
vec![6, 7, 8, 9, 10],
vec![14, 14, 14, 14, 14], // fliers
];
// x ticks and labels
let ncol = data[0].len();
let ticks: Vec<_> = (1..(ncol + 1)).into_iter().collect();
let labels = ["A", "B", "C", "D", "E"];
// boxplot object and options
let mut boxes = Boxplot::new();
boxes.draw_mat(&data);
// save figure
let mut plot = Plot::new();
plot.add(&boxes)
.set_title("boxplot documentation test")
.set_ticks_x_labels(&ticks, &labels)
.save("/tmp/plotpy/doc_tests/doc_boxplot_1.svg")?;
Ok(())
}§More examples
See also integration test in the tests directory.
Implementations§
Source§impl Boxplot
impl Boxplot
Sourcepub fn draw<T>(&mut self, data: &Vec<Vec<T>>)
pub fn draw<T>(&mut self, data: &Vec<Vec<T>>)
Draws the box plot given a nested list
§Input
data– Is a sequence of 1D arrays such that a boxplot is drawn for each array in the sequence. From Matplotlib
Sourcepub fn draw_mat<'a, T, U>(&mut self, data: &'a T)
pub fn draw_mat<'a, T, U>(&mut self, data: &'a T)
Draws the box plot given a 2D array (matrix)
§Input
data– Is a 2D array (matrix) such that a boxplot is drawn for each column in the matrix. From Matplotlib
Sourcepub fn set_symbol(&mut self, symbol: &str) -> &mut Self
pub fn set_symbol(&mut self, symbol: &str) -> &mut Self
Sets the symbol for the fliers
Sourcepub fn set_horizontal(&mut self, flag: bool) -> &mut Self
pub fn set_horizontal(&mut self, flag: bool) -> &mut Self
Enables drawing horizontal boxes
Sourcepub fn set_whisker(&mut self, whisker: f64) -> &mut Self
pub fn set_whisker(&mut self, whisker: f64) -> &mut Self
Sets the position of the whiskers
The default value of whisker = 1.5 corresponds to Tukey’s original definition of boxplots.
Sourcepub fn set_positions(&mut self, positions: &[f64]) -> &mut Self
pub fn set_positions(&mut self, positions: &[f64]) -> &mut Self
Sets the positions of the boxes
Sourcepub fn set_no_fliers(&mut self, flag: bool) -> &mut Self
pub fn set_no_fliers(&mut self, flag: bool) -> &mut Self
Disables the fliers
Sourcepub fn set_patch_artist(&mut self, flag: bool) -> &mut Self
pub fn set_patch_artist(&mut self, flag: bool) -> &mut Self
Enables the use of Patch artist to draw boxes instead of Line2D artist
Sourcepub fn set_medianprops(&mut self, props: &str) -> &mut Self
pub fn set_medianprops(&mut self, props: &str) -> &mut Self
Set the median properties.
Sourcepub fn set_boxprops(&mut self, props: &str) -> &mut Self
pub fn set_boxprops(&mut self, props: &str) -> &mut Self
Set the properties of the box
Sourcepub fn set_whiskerprops(&mut self, props: &str) -> &mut Self
pub fn set_whiskerprops(&mut self, props: &str) -> &mut Self
Set the properties of the whisker
Trait Implementations§
Source§impl GraphMaker for Boxplot
impl GraphMaker for Boxplot
Source§fn get_buffer<'a>(&'a self) -> &'a String
fn get_buffer<'a>(&'a self) -> &'a String
Returns the text buffer with Python3 commands
Source§fn clear_buffer(&mut self)
fn clear_buffer(&mut self)
Clear the text buffer with Python commands
Auto Trait Implementations§
impl Freeze for Boxplot
impl RefUnwindSafe for Boxplot
impl Send for Boxplot
impl Sync for Boxplot
impl Unpin for Boxplot
impl UnwindSafe for Boxplot
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