pub struct PieChart { /* private fields */ }Expand description
A structure representing a pie chart.
The PieChart struct allows for the creation and customization of pie charts, supporting
features such as labels, hole size for donut-style charts, slice pulling, rotation, faceting, and customizable plot titles.
It is ideal for visualizing proportions and distributions in categorical data.
§Arguments
data- A reference to theDataFramecontaining the data to be plotted.labels- A string slice specifying the column name to be used for slice labels.facet- An optional string slice specifying the column name to be used for creating facets (small multiples).facet_config- An optional reference to aFacetConfigstruct for customizing facet layout and behavior.hole- An optionalf64value specifying the size of the hole in the center of the pie chart. A value of0.0creates a full pie chart, while a value closer to1.0creates a thinner ring.pull- An optionalf64value specifying the fraction by which each slice should be pulled out from the center.rotation- An optionalf64value specifying the starting angle (in degrees) of the first slice.colors- An optional vector ofRgbvalues specifying colors for consistent slice colors across facets.plot_title- An optionalTextstruct specifying the title of the plot.legend_title- An optionalTextstruct specifying the title of the legend.legend- An optional reference to aLegendstruct for customizing the legend of the plot (e.g., positioning, font, etc.).
§Example
§Basic Pie Chart with Customization
use plotlars::{PieChart, Plot, Text};
use polars::prelude::*;
let dataset = LazyCsvReader::new(PlPath::new("data/penguins.csv"))
.finish()
.unwrap()
.select([col("species")])
.collect()
.unwrap();
PieChart::builder()
.data(&dataset)
.labels("species")
.hole(0.4)
.pull(0.01)
.rotation(20.0)
.plot_title(
Text::from("Pie Chart")
.font("Arial")
.size(18)
.x(0.485)
)
.build()
.plot();
Implementations§
Source§impl PieChart
impl PieChart
Sourcepub fn builder<'f1, 'f2, 'f3, 'f4, 'f5>() -> PieChartBuilder<'f1, 'f2, 'f3, 'f4, 'f5>
pub fn builder<'f1, 'f2, 'f3, 'f4, 'f5>() -> PieChartBuilder<'f1, 'f2, 'f3, 'f4, 'f5>
Examples found in repository?
examples/piechart.rs (line 12)
4fn main() {
5 let dataset = LazyCsvReader::new(PlPath::new("data/penguins.csv"))
6 .finish()
7 .unwrap()
8 .select([col("species")])
9 .collect()
10 .unwrap();
11
12 PieChart::builder()
13 .data(&dataset)
14 .labels("species")
15 .hole(0.4)
16 .pull(0.01)
17 .rotation(20.0)
18 .plot_title(Text::from("Pie Chart").font("Arial").size(18).x(0.485))
19 .build()
20 .plot();
21}More examples
examples/faceting.rs (line 407)
392fn piechart_example() {
393 let dataset = CsvReadOptions::default()
394 .with_has_header(true)
395 .try_into_reader_with_file_path(Some("data/industry_region.csv".into()))
396 .unwrap()
397 .finish()
398 .unwrap();
399
400 let facet_config = FacetConfig::new()
401 .cols(3)
402 .scales(FacetScales::Free)
403 .h_gap(0.08)
404 .v_gap(0.12)
405 .title_style(Text::from("").size(13).color(Rgb(60, 60, 60)));
406
407 PieChart::builder()
408 .data(&dataset)
409 .labels("category")
410 .facet("region")
411 .facet_config(&facet_config)
412 .colors(vec![
413 Rgb(192, 57, 43),
414 Rgb(39, 174, 96),
415 Rgb(41, 128, 185),
416 Rgb(243, 156, 18),
417 ])
418 .rotation(25.0)
419 .pull(0.02)
420 .plot_title(Text::from("Industry Analysis").size(18))
421 .build()
422 .plot();
423}Trait Implementations§
Auto Trait Implementations§
impl Freeze for PieChart
impl !RefUnwindSafe for PieChart
impl !Send for PieChart
impl !Sync for PieChart
impl Unpin for PieChart
impl !UnwindSafe for PieChart
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