Skip to main content

FacetConfig

Struct FacetConfig 

Source
pub struct FacetConfig {
    pub rows: Option<usize>,
    pub cols: Option<usize>,
    pub scales: FacetScales,
    pub h_gap: Option<f64>,
    pub v_gap: Option<f64>,
    pub title_style: Option<Text>,
    pub sorter: Option<fn(&str, &str) -> Ordering>,
    pub highlight_facet: bool,
    pub unhighlighted_color: Option<Rgb>,
}
Expand description

A structure representing facet configuration for creating small multiples.

The FacetConfig struct allows customization of faceted plots including grid layout, scale behavior, spacing, title styling, custom ordering, and highlighting options. Faceting splits data by a categorical variable to create multiple subplots arranged in a grid, making it easy to compare patterns across categories.

§Example

use plotlars::{SurfacePlot, FacetConfig, Plot, Palette, Text};
use polars::prelude::*;
use ndarray::Array;

let n: usize = 50;
let (x_base, _): (Vec<f64>, Option<usize>) =
    Array::linspace(-5., 5., n).into_raw_vec_and_offset();
let (y_base, _): (Vec<f64>, Option<usize>) =
    Array::linspace(-5., 5., n).into_raw_vec_and_offset();

let mut x_all = Vec::new();
let mut y_all = Vec::new();
let mut z_all = Vec::new();
let mut category_all = Vec::new();

type SurfaceFunction = Box<dyn Fn(f64, f64) -> f64>;
let functions: Vec<(&str, SurfaceFunction)> = vec![
    (
        "Sine Wave",
        Box::new(|xi: f64, yj: f64| (xi * xi + yj * yj).sqrt().sin()),
    ),
    ("Saddle", Box::new(|xi: f64, yj: f64| xi * xi - yj * yj)),
    (
        "Gaussian",
        Box::new(|xi: f64, yj: f64| (-0.5 * (xi * xi + yj * yj)).exp()),
    ),
];

for (name, func) in &functions {
    for &xi in x_base.iter() {
        for &yj in y_base.iter() {
            x_all.push(xi);
            y_all.push(yj);
            z_all.push(func(xi, yj));
            category_all.push(*name);
        }
    }
}

let dataset = df![
    "x" => &x_all,
    "y" => &y_all,
    "z" => &z_all,
    "function" => &category_all,
]
.unwrap();

SurfacePlot::builder()
    .data(&dataset)
    .x("x")
    .y("y")
    .z("z")
    .facet("function")
    .facet_config(&FacetConfig::new().cols(3).rows(1).h_gap(0.08).v_gap(0.12))
    .plot_title(
        Text::from("3D Mathematical Functions")
            .font("Arial")
            .size(20),
    )
    .color_scale(Palette::Viridis)
    .opacity(0.9)
    .build()
    .plot();

Example

Fields§

§rows: Option<usize>§cols: Option<usize>§scales: FacetScales§h_gap: Option<f64>§v_gap: Option<f64>§title_style: Option<Text>§sorter: Option<fn(&str, &str) -> Ordering>§highlight_facet: bool§unhighlighted_color: Option<Rgb>

Implementations§

Source§

impl FacetConfig

Source

pub fn new() -> Self

Creates a new FacetConfig instance with default values.

By default, the grid dimensions are automatically calculated, scales are fixed across all facets, and highlighting is disabled.

Source

pub fn rows(self, rows: usize) -> Self

Sets the number of rows in the facet grid.

When specified, the grid will have exactly this many rows, and the number of columns will be calculated automatically based on the number of facets. If not specified, both dimensions are calculated automatically.

§Argument
  • rows - A usize value specifying the number of rows (must be greater than 0).
§Panics

Panics if rows is 0.

Source

pub fn cols(self, cols: usize) -> Self

Sets the number of columns in the facet grid.

When specified, the grid will have exactly this many columns, and the number of rows will be calculated automatically based on the number of facets. If not specified, both dimensions are calculated automatically.

§Argument
  • cols - A usize value specifying the number of columns (must be greater than 0).
§Panics

Panics if cols is 0.

Source

pub fn scales(self, scales: FacetScales) -> Self

Sets the axis scale behavior across facets.

Controls whether facets share the same axis ranges (Fixed) or have independent scales (Free, FreeX, or FreeY). Fixed scales make it easier to compare values across facets, while free scales allow each facet to use its optimal range.

§Argument
  • scales - A FacetScales enum value specifying the scale behavior.
Source

pub fn h_gap(self, gap: f64) -> Self

Sets the horizontal spacing between columns.

The gap is specified as a proportion of the plot width, with typical values ranging from 0.0 (no gap) to 0.2 (20% gap). If not specified, plotly’s default spacing is used.

§Argument
  • gap - A f64 value from 0.0 to 1.0 representing the relative gap size.
§Panics

Panics if gap is negative, NaN, or infinite.

Source

pub fn v_gap(self, gap: f64) -> Self

Sets the vertical spacing between rows.

The gap is specified as a proportion of the plot height, with typical values ranging from 0.0 (no gap) to 0.2 (20% gap). If not specified, plotly’s default spacing is used.

§Argument
  • gap - A f64 value from 0.0 to 1.0 representing the relative gap size.
§Panics

Panics if gap is negative, NaN, or infinite.

Source

pub fn title_style<T: Into<Text>>(self, style: T) -> Self

Sets the styling for facet labels.

Controls the font, size, and color of the category labels that appear above each facet. If not specified, plotly’s default text styling is used.

§Argument
  • style - A Text component or any type that can be converted into Text, specifying the styling options for facet titles.
Source

pub fn sorter(self, f: fn(&str, &str) -> Ordering) -> Self

Sets a custom sorting function for facet order.

By default, facets are ordered alphabetically by category name. This method allows you to specify a custom comparison function to control the order in which facets appear in the grid.

§Argument
  • f - A function that takes two string slices and returns an Ordering, following the same signature as str::cmp.
§Example
use plotlars::FacetConfig;
use std::cmp::Ordering;

// Reverse alphabetical order
let config = FacetConfig::new()
    .sorter(|a, b| b.cmp(a));
Source

pub fn highlight_facet(self, highlight: bool) -> Self

Enables or disables facet highlighting mode.

When enabled, each facet shows all data from all categories, but emphasizes the data for the current facet’s category while displaying other categories in a muted color. This provides visual context by showing the full data distribution while focusing attention on the current facet.

§Argument
  • highlight - A boolean value: true to enable highlighting, false to disable.
Source

pub fn unhighlighted_color(self, color: Rgb) -> Self

Sets the color for unhighlighted data points in highlighting mode.

This setting only takes effect when highlight_facet is enabled. It specifies the color used for data points that belong to other categories (not the current facet’s category). If not specified, a default grey color is used.

§Argument
  • color - An Rgb value specifying the color for unhighlighted data.

Trait Implementations§

Source§

impl Clone for FacetConfig

Source§

fn clone(&self) -> FacetConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Default for FacetConfig

Source§

fn default() -> FacetConfig

Returns the “default value” for a type. 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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Key for T
where T: Clone,

Source§

fn align() -> usize

The alignment necessary for the key. Must return a power of two.
Source§

fn size(&self) -> usize

The size of the key in bytes.
Source§

unsafe fn init(&self, ptr: *mut u8)

Initialize the key in the given memory location. Read more
Source§

unsafe fn get<'a>(ptr: *const u8) -> &'a T

Get a reference to the key from the given memory location. Read more
Source§

unsafe fn drop_in_place(ptr: *mut u8)

Drop the key in place. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> PlanCallbackArgs for T

Source§

impl<T> PlanCallbackOut for T