pub struct BoxPlot {
pub groups: Vec<BoxGroup>,
pub color: String,
pub width: f64,
pub legend_label: Option<String>,
pub group_colors: Option<Vec<String>>,
pub overlay: Option<StripStyle>,
pub overlay_color: String,
pub overlay_size: f64,
pub overlay_seed: u64,
pub horizontal: bool,
}Expand description
Builder for a box plot (box-and-whisker plot).
Displays the five-number summary for one or more groups of values. Whiskers use the Tukey 1.5×IQR rule; values outside the whiskers are not drawn automatically (use an overlay to show individual points). Groups are rendered side-by-side in the order they are added.
§Example
use kuva::plot::BoxPlot;
use kuva::backend::svg::SvgBackend;
use kuva::render::render::render_multiple;
use kuva::render::layout::Layout;
use kuva::render::plots::Plot;
let plot = BoxPlot::new()
.with_group("Control", vec![4.1, 5.0, 5.3, 5.8, 6.2, 7.0])
.with_group("Treated", vec![5.5, 6.1, 6.4, 7.2, 7.8, 8.5])
.with_color("steelblue");
let plots = vec![Plot::Box(plot)];
let layout = Layout::auto_from_plots(&plots)
.with_title("Control vs. Treated")
.with_x_label("Group")
.with_y_label("Value");
let svg = SvgBackend.render_scene(&render_multiple(plots, layout));
std::fs::write("boxplot.svg", svg).unwrap();Fields§
§groups: Vec<BoxGroup>§color: String§width: f64§legend_label: Option<String>§group_colors: Option<Vec<String>>§overlay: Option<StripStyle>§overlay_color: String§overlay_size: f64§overlay_seed: u64§horizontal: boolImplementations§
Source§impl BoxPlot
impl BoxPlot
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a box plot with default settings.
Defaults: color "black", box width 0.8,
overlay color "rgba(0,0,0,0.45)", overlay point size 3.0.
Sourcepub fn with_group<T, U, I>(self, label: T, values: I) -> Self
pub fn with_group<T, U, I>(self, label: T, values: I) -> Self
Add a group (one box) with a label and raw values.
Groups are rendered left-to-right in the order they are added. The renderer computes Q1, median, Q3, and Tukey 1.5×IQR whiskers from the supplied values.
let plot = BoxPlot::new()
.with_group("A", vec![1.0, 2.5, 3.0, 3.5, 4.0, 5.0])
.with_group("B", vec![2.0, 3.0, 3.8, 4.2, 4.8, 6.0]);Sourcepub fn with_color<S: Into<String>>(self, color: S) -> Self
pub fn with_color<S: Into<String>>(self, color: S) -> Self
Set the box fill color (CSS color string, e.g. "steelblue").
This color is applied to all boxes. Use the same color for all
groups and distinguish them by position, or layer multiple
BoxPlot instances in a Vec<Plot> with different colors.
Sourcepub fn with_group_colors<S, I>(self, colors: I) -> Self
pub fn with_group_colors<S, I>(self, colors: I) -> Self
Set per-group fill colors.
Colors are matched to groups by position. If the list is shorter than
the number of groups, the uniform color from with_color
is used as a fallback.
Sourcepub fn with_width(self, width: f64) -> Self
pub fn with_width(self, width: f64) -> Self
Set the box width as a fraction of the category slot (default 0.8).
Complement of with_gap: width = 1.0 - gap.
Sourcepub fn with_gap(self, gap: f64) -> Self
pub fn with_gap(self, gap: f64) -> Self
Set the gap between boxes as a fraction of the category slot (default 0.2).
Complement of with_width: gap = 1.0 - width.
Sourcepub fn with_legend<S: Into<String>>(self, label: S) -> Self
pub fn with_legend<S: Into<String>>(self, label: S) -> Self
Attach a legend label to this box plot.
Sourcepub fn with_strip(self, jitter: f64) -> Self
pub fn with_strip(self, jitter: f64) -> Self
Overlay individual data points as a jittered strip.
jitter controls the horizontal spread of the points (in data
units). A value of 0.2 is a reasonable default. Points are
placed on top of the box — use a semi-transparent
with_overlay_color so the box
remains visible underneath.
Sourcepub fn with_swarm_overlay(self) -> Self
pub fn with_swarm_overlay(self) -> Self
Overlay individual data points as a beeswarm.
Points are spread horizontally to avoid overlap, giving a clearer view of the data density than a jittered strip. Useful for smaller datasets (N < ~200 per group) where individual points are meaningful.
Sourcepub fn with_overlay_color<S: Into<String>>(self, color: S) -> Self
pub fn with_overlay_color<S: Into<String>>(self, color: S) -> Self
Set the fill color for overlay points (default "rgba(0,0,0,0.45)").
A semi-transparent color is recommended so the box underneath remains visible.
Sourcepub fn with_overlay_size(self, size: f64) -> Self
pub fn with_overlay_size(self, size: f64) -> Self
Set the radius of overlay points in pixels (default 3.0).
Sourcepub fn with_horizontal(self, h: bool) -> Self
pub fn with_horizontal(self, h: bool) -> Self
Render groups along the Y-axis and data values along the X-axis (default false).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BoxPlot
impl RefUnwindSafe for BoxPlot
impl Send for BoxPlot
impl Sync for BoxPlot
impl Unpin for BoxPlot
impl UnsafeUnpin 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
Source§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
Source§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.