Skip to main content

ViolinArtist

Struct ViolinArtist 

Source
pub struct ViolinArtist {
    pub datasets: Vec<Vec<f64>>,
    pub positions: Option<Vec<f64>>,
    pub widths: f64,
    pub show_median: bool,
    pub show_quartiles: bool,
    pub color: Color,
    pub alpha: f64,
    pub label: Option<String>,
    pub bw_method: f64,
}
Expand description

A violin plot showing the probability density of data distributions.

Each dataset produces a mirrored kernel density estimate (KDE) shape, similar to a boxplot but showing the full distribution. Optional median and quartile lines can be drawn inside the violin.

Fields§

§datasets: Vec<Vec<f64>>

One dataset per violin. Each inner Vec<f64> contains the raw values.

§positions: Option<Vec<f64>>

Optional x-positions for each violin. Defaults to 1, 2, 3, etc.

§widths: f64

Maximum width of each violin shape.

§show_median: bool

Whether to draw a median line inside each violin.

§show_quartiles: bool

Whether to draw Q1/Q3 quartile lines inside each violin.

§color: Color

Fill color of the violin shapes.

§alpha: f64

Opacity from 0.0 (fully transparent) to 1.0 (fully opaque).

§label: Option<String>

Optional legend label.

§bw_method: f64

KDE bandwidth override. When <= 0.0, Silverman’s rule is used.

Implementations§

Source§

impl ViolinArtist

Source

pub fn color(&mut self, color: Color) -> &mut Self

Sets the fill color.

Applies the given Color to every violin rendered by this artist.

Source

pub fn label(&mut self, label: &str) -> &mut Self

Sets the legend label.

When a legend is displayed on the figure, this label will appear next to the color swatch for this violin plot.

Source

pub fn alpha(&mut self, alpha: f64) -> &mut Self

Sets the opacity.

The value is clamped to the range [0.0, 1.0], where 0.0 is fully transparent and 1.0 is fully opaque.

Source

pub fn widths(&mut self, widths: f64) -> &mut Self

Sets the maximum width of each violin shape.

The value is clamped to [0.1, 2.0]. This controls the visual width of the widest part of the violin.

Source

pub fn positions(&mut self, positions: Vec<f64>) -> &mut Self

Sets the x-positions for each violin.

When None (the default), violins are placed at 1.0, 2.0, 3.0, etc.

Source

pub fn show_median(&mut self, show: bool) -> &mut Self

Controls whether the median line is drawn.

When true (the default), a horizontal line is drawn at the median of each dataset inside the violin shape.

Source

pub fn show_quartiles(&mut self, show: bool) -> &mut Self

Controls whether Q1/Q3 quartile lines are drawn.

When true (the default), thin horizontal lines are drawn at the first and third quartiles inside the violin shape.

Source

pub fn bw_method(&mut self, bw: f64) -> &mut Self

Sets the KDE bandwidth manually.

Overrides the automatically computed Silverman’s rule bandwidth. A value of 0.0 or negative resets to automatic bandwidth selection.

Source

pub fn position_for(&self, index: usize) -> f64

Returns the x-position for a given violin index.

Uses custom positions if set, otherwise defaults to 1-based indexing.

Source

pub fn data_bounds(&self) -> (f64, f64, f64, f64)

Computes the data-space bounding box (xmin, xmax, ymin, ymax).

The x-bounds span from the leftmost position minus half the max width to the rightmost position plus half the max width. The y-bounds span from the minimum data value to the maximum data value across all datasets. Falls back to (0.0, 1.0, 0.0, 1.0) when there are no datasets.

Trait Implementations§

Source§

impl Clone for ViolinArtist

Source§

fn clone(&self) -> ViolinArtist

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ViolinArtist

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.