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();
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
impl FacetConfig
Sourcepub fn new() -> Self
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.
Sourcepub fn rows(self, rows: usize) -> Self
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- Ausizevalue specifying the number of rows (must be greater than 0).
§Panics
Panics if rows is 0.
Sourcepub fn cols(self, cols: usize) -> Self
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- Ausizevalue specifying the number of columns (must be greater than 0).
§Panics
Panics if cols is 0.
Sourcepub fn scales(self, scales: FacetScales) -> Self
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- AFacetScalesenum value specifying the scale behavior.
Sourcepub fn h_gap(self, gap: f64) -> Self
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- Af64value from 0.0 to 1.0 representing the relative gap size.
§Panics
Panics if gap is negative, NaN, or infinite.
Sourcepub fn v_gap(self, gap: f64) -> Self
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- Af64value from 0.0 to 1.0 representing the relative gap size.
§Panics
Panics if gap is negative, NaN, or infinite.
Sourcepub fn title_style<T: Into<Text>>(self, style: T) -> Self
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- ATextcomponent or any type that can be converted intoText, specifying the styling options for facet titles.
Sourcepub fn sorter(self, f: fn(&str, &str) -> Ordering) -> Self
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 anOrdering, following the same signature asstr::cmp.
§Example
use plotlars::FacetConfig;
use std::cmp::Ordering;
// Reverse alphabetical order
let config = FacetConfig::new()
.sorter(|a, b| b.cmp(a));Sourcepub fn highlight_facet(self, highlight: bool) -> Self
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:trueto enable highlighting,falseto disable.
Sourcepub fn unhighlighted_color(self, color: Rgb) -> Self
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- AnRgbvalue specifying the color for unhighlighted data.
Trait Implementations§
Source§impl Clone for FacetConfig
impl Clone for FacetConfig
Source§fn clone(&self) -> FacetConfig
fn clone(&self) -> FacetConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for FacetConfig
impl Default for FacetConfig
Source§fn default() -> FacetConfig
fn default() -> FacetConfig
Auto Trait Implementations§
impl Freeze for FacetConfig
impl RefUnwindSafe for FacetConfig
impl Send for FacetConfig
impl Sync for FacetConfig
impl Unpin for FacetConfig
impl UnsafeUnpin for FacetConfig
impl UnwindSafe for FacetConfig
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Key for Twhere
T: Clone,
impl<T> Key for Twhere
T: Clone,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().