pub struct Boxplot { /* private fields */ }Expand description
Draw a box and whisker plot
Each box shows the median, quartiles (Q1/Q3), and whiskers (default: 1.5 × IQR). Outlier points (fliers) are drawn beyond the whiskers.
Two data formats are supported:
- Nested list (via
draw): one box per sub-array (variable group sizes) - 2D matrix (via
draw_mat): one box per column (equal group sizes)
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 set_symbol(&mut self, symbol: &str) -> &mut Self
pub fn set_symbol(&mut self, symbol: &str) -> &mut Self
Sets the marker symbol for outlier points (fliers)
Example: "b+" for blue crosses, "rx" for red x-marks.
Sourcepub fn set_horizontal(&mut self, flag: bool) -> &mut Self
pub fn set_horizontal(&mut self, flag: bool) -> &mut Self
Enables drawing horizontal boxes instead of vertical
When true, the boxplot is rotated 90° clockwise so categories
appear on the y-axis.
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
Overrides the default x-axis positions of the boxes
By default boxes are placed at sequential integer positions (1, 2, 3, …). Use this to spread or group boxes at custom locations.
Sourcepub fn set_no_fliers(&mut self, flag: bool) -> &mut Self
pub fn set_no_fliers(&mut self, flag: bool) -> &mut Self
Hides outlier points (fliers) when true
Outliers are data points beyond 1.5 × IQR from the quartiles.
Sourcepub fn set_patch_artist(&mut self, flag: bool) -> &mut Self
pub fn set_patch_artist(&mut self, flag: bool) -> &mut Self
Enables Patch artist drawing so boxes can be filled with color
By default Matplotlib uses Line2D to draw boxes. Setting this to true
allows set_boxprops to fill boxes with color.
Sourcepub fn set_medianprops(&mut self, props: &str) -> &mut Self
pub fn set_medianprops(&mut self, props: &str) -> &mut Self
Sets the median line properties as a Python dict string
Example: "{'color': 'red', 'linewidth': 2}"
Sourcepub fn set_boxprops(&mut self, props: &str) -> &mut Self
pub fn set_boxprops(&mut self, props: &str) -> &mut Self
Sets the box body properties as a Python dict string
Requires set_patch_artist(true).
Example: "{'facecolor': 'lightblue', 'edgecolor': 'black'}"
Sourcepub fn set_whiskerprops(&mut self, props: &str) -> &mut Self
pub fn set_whiskerprops(&mut self, props: &str) -> &mut Self
Sets the whisker line properties as a Python dict string
Example: "{'linestyle': '--', 'color': 'gray'}"