pub struct SankeyDiagram { /* private fields */ }
Expand description
A structure representing a Sankey diagram.
The SankeyDiagram
struct enables the creation of Sankey diagrams, which visualize flows
between discrete nodes with link widths proportional to the magnitude of the flow. It
offers extensive configuration options for flow orientation, node arrangement, spacing,
thickness, and coloring, as well as axis and title customization. Users can specify a
single uniform color or per-item colors for both nodes and links, adjust padding between
nodes, set node thickness, and supply custom titles and axis labels to produce clear,
publication-quality flow visualizations.
§Arguments
data
– A reference to theDataFrame
containing the data to be plotted.sources
– A string slice naming the column indata
that contains the source node for each flow.targets
– A string slice naming the column indata
that contains the target node for each flow.values
– A string slice naming the column indata
that contains the numeric value of each flow.orientation
– An optionalOrientation
enum to set the overall direction of the diagram (e.g.Orientation::Horizontal
orOrientation::Vertical
).arrangement
– An optionalArrangement
enum to choose the node-layout algorithm (e.g.Arrangement::Snap
,Arrangement::Perpendicular
, etc.).pad
– An optionalusize
specifying the padding (in pixels) between adjacent nodes.thickness
– An optionalusize
defining the uniform thickness (in pixels) of all nodes.node_color
– An optionalRgb
value to apply a single uniform color to every node.node_colors
– An optionalVec<Rgb>
supplying individual colors for each node in order.link_color
– An optionalRgb
value to apply a single uniform color to every link.link_colors
– An optionalVec<Rgb>
supplying individual colors for each link in order.plot_title
– An optionalText
struct for setting the overall title of the plot.
§Example
use polars::prelude::*;
use plotlars::{Arrangement, SankeyDiagram, Orientation, Plot, Rgb, Text};
let dataset = df![
"source" => ["A1", "A2", "A1", "B1", "B2", "B2"],
"target" => &["B1", "B2", "B2", "C1", "C1", "C2"],
"value" => &[8, 4, 2, 8, 4, 2],
]
.unwrap();
SankeyDiagram::builder()
.data(&dataset)
.sources("source")
.targets("target")
.values("value")
.orientation(Orientation::Horizontal)
.arrangement(Arrangement::Freeform)
.node_colors(vec![
Rgb(222, 235, 247),
Rgb(198, 219, 239),
Rgb(158, 202, 225),
Rgb(107, 174, 214),
Rgb( 66, 146, 198),
Rgb( 33, 113, 181),
])
.link_colors(vec![
Rgb(222, 235, 247),
Rgb(198, 219, 239),
Rgb(158, 202, 225),
Rgb(107, 174, 214),
Rgb( 66, 146, 198),
Rgb( 33, 113, 181),
])
.pad(20)
.thickness(30)
.plot_title(
Text::from("Sankey Diagram")
.font("Arial")
.size(18)
)
.build()
.plot();
Implementations§
Source§impl SankeyDiagram
impl SankeyDiagram
Trait Implementations§
Source§impl Clone for SankeyDiagram
impl Clone for SankeyDiagram
Source§fn clone(&self) -> SankeyDiagram
fn clone(&self) -> SankeyDiagram
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for SankeyDiagram
impl !RefUnwindSafe for SankeyDiagram
impl !Send for SankeyDiagram
impl !Sync for SankeyDiagram
impl Unpin for SankeyDiagram
impl !UnwindSafe for SankeyDiagram
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
Mutably borrows from an owned value. Read more
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> ⓘ
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 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> ⓘ
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