Skip to main content

BoxPlot

Struct BoxPlot 

Source
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: bool

Implementations§

Source§

impl BoxPlot

Source

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.

Source

pub fn with_group<T, U, I>(self, label: T, values: I) -> Self
where T: Into<String>, I: IntoIterator<Item = U>, U: Into<f64>,

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]);
Source

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.

Source

pub fn with_group_colors<S, I>(self, colors: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

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.

Source

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.

Source

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.

Source

pub fn with_legend<S: Into<String>>(self, label: S) -> Self

Attach a legend label to this box plot.

Source

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.

Source

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.

Source

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.

Source

pub fn with_overlay_size(self, size: f64) -> Self

Set the radius of overlay points in pixels (default 3.0).

Source

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§

Source§

impl Default for BoxPlot

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<BoxPlot> for Plot

Source§

fn from(p: BoxPlot) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Finish for T

Source§

fn finish(self)

Does nothing but move self, equivalent to drop.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

Source§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
Source§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

Source§

fn to_owned_table(&self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.