Skip to main content

HistArtist

Struct HistArtist 

Source
pub struct HistArtist {
    pub data: Series,
    pub bins: usize,
    pub bin_edges: Vec<f64>,
    pub counts: Vec<f64>,
    pub color: Color,
    pub label: Option<String>,
    pub alpha: f64,
    pub density: bool,
}
Expand description

A histogram showing the frequency distribution of a single data series.

The raw data is retained in data, but the binning results (bin_edges and counts) are expected to be pre-computed when the artist is created (typically by the histogram chart builder). This avoids re-binning during every render pass.

When density is true, the counts vector stores probability density values (each count divided by n * bin_width) rather than raw counts, so that the total area under the histogram integrates to 1.0.

Fields§

§data: Series

The original (un-binned) data values.

§bins: usize

The requested number of bins (used for display/debugging; the actual bin count is bin_edges.len() - 1).

§bin_edges: Vec<f64>

Sorted bin edges of length bins + 1. The i-th bin spans [bin_edges[i], bin_edges[i+1]).

§counts: Vec<f64>

The count (or density) for each bin. Length equals bin_edges.len() - 1.

§color: Color

Fill color of the histogram bars.

§label: Option<String>

Optional legend label. When Some, the histogram appears in the legend.

§alpha: f64

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

§density: bool

When true, counts stores probability density instead of raw counts.

Implementations§

Source§

impl HistArtist

Source

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

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

The x-axis spans from the first bin edge to the last bin edge. The y-axis spans from 0.0 to the tallest bin count (or density value). Returns (0.0, 1.0, 0.0, 1.0) when there are no bin edges.

Source§

impl HistArtist

Source

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

Sets the bar fill color for every bin in the histogram.

Accepts any Color value, which can be constructed from RGB components, hex strings, or named color constants.

§Arguments
  • color - The Color to fill each histogram bar with.
§Examples
artist.color(Color::TAB_BLUE);
Source

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

Sets the legend label for this histogram.

When a label is set, the histogram will appear in the legend if one is displayed on the axes. Pass an empty string or omit this call to exclude the histogram from the legend. Calling this method again overwrites any previously set label.

§Arguments
  • label - A string slice that will be stored as the legend entry.
§Examples
artist.label("Scores");
Source

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

Sets the opacity (0.0 = fully transparent, 1.0 = fully opaque).

The value is clamped to the [0.0, 1.0] range. The default opacity is determined by the active theme (typically 0.7 for histograms so that overlapping distributions remain visible).

§Arguments
  • alpha - The desired opacity level.
§Examples
artist.alpha(0.5); // 50% transparent
Source

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

Controls whether the histogram displays probability density instead of raw counts.

When density is true, the counts vector is normalized so that the total area under the histogram integrates to 1.0. Each bin’s value becomes count / (total * bin_width). This is useful for comparing distributions with different sample sizes or overlaying a probability density function.

When density is false (the default), the counts vector stores raw frequency counts.

§Arguments
  • density - If true, normalize the histogram to unit area.
§Examples
artist.density(true); // show probability density

Trait Implementations§

Source§

impl Clone for HistArtist

Source§

fn clone(&self) -> HistArtist

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 HistArtist

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.