pub struct ScatterPolar { /* private fields */ }Expand description
A structure representing a scatter polar plot.
The ScatterPolar struct facilitates the creation and customization of polar scatter plots with various options
for data selection, grouping, layout configuration, and aesthetic adjustments. It supports grouping of data,
customization of marker shapes, colors, sizes, line styles, and comprehensive layout customization
including titles and legends.
§Arguments
data- A reference to theDataFramecontaining the data to be plotted.theta- A string slice specifying the column name to be used for the angular coordinates (in degrees).r- A string slice specifying the column name to be used for the radial coordinates.group- An optional string slice specifying the column name to be used for grouping data points.sort_groups_by- Optional comparatorfn(&str, &str) -> std::cmp::Orderingto control group ordering. Groups are sorted lexically by default.facet- An optional string slice specifying the column name to be used for faceting (creating multiple subplots).facet_config- An optional reference to aFacetConfigstruct for customizing facet behavior (grid dimensions, scales, gaps, etc.).mode- An optionalModespecifying the drawing mode (lines, markers, or both). Defaults to markers.opacity- An optionalf64value specifying the opacity of the plot elements (range: 0.0 to 1.0).fill- An optionalFilltype specifying how to fill the area under the trace.size- An optionalusizespecifying the size of the markers.color- An optionalRgbvalue specifying the color of the markers. This is used whengroupis not specified.colors- An optional vector ofRgbvalues specifying the colors for the markers. This is used whengroupis specified to differentiate between groups.shape- An optionalShapespecifying the shape of the markers. This is used whengroupis not specified.shapes- An optional vector ofShapevalues specifying multiple shapes for the markers when plotting multiple groups.width- An optionalf64specifying the width of the lines.line- An optionalLineStylespecifying the style of the line (e.g., solid, dashed).lines- An optional vector ofLineStyleenums specifying the styles of lines for multiple traces.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
use plotlars::{Legend, Line, Mode, Plot, Rgb, ScatterPolar, Shape, Text};
use polars::prelude::*;
let dataset = LazyCsvReader::new(PlPath::new("data/product_comparison_polar.csv"))
.finish()
.unwrap()
.collect()
.unwrap();
ScatterPolar::builder()
.data(&dataset)
.theta("angle")
.r("score")
.group("product")
.mode(Mode::LinesMarkers)
.colors(vec![
Rgb(255, 99, 71),
Rgb(60, 179, 113),
])
.shapes(vec![
Shape::Circle,
Shape::Square,
])
.lines(vec![
Line::Solid,
Line::Dash,
])
.width(2.5)
.size(8)
.plot_title(
Text::from("Scatter Polar Plot")
.font("Arial")
.size(24)
)
.legend_title(
Text::from("Products")
.font("Arial")
.size(14)
)
.legend(
&Legend::new()
.x(0.85)
.y(0.95)
)
.build()
.plot();
Implementations§
Source§impl ScatterPolar
impl ScatterPolar
Sourcepub fn builder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7>() -> ScatterPolarBuilder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7>
pub fn builder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7>() -> ScatterPolarBuilder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7>
Examples found in repository?
examples/scatterpolar.rs (line 29)
18fn basic_scatter_polar() {
19 // Create sample data - wind direction and speed
20 let directions = vec![0., 45., 90., 135., 180., 225., 270., 315., 360.];
21 let speeds = vec![5.0, 7.5, 10.0, 8.5, 6.0, 4.5, 3.0, 2.5, 5.0];
22
23 let dataset = DataFrame::new(vec![
24 Column::new("direction".into(), directions),
25 Column::new("speed".into(), speeds),
26 ])
27 .unwrap();
28
29 ScatterPolar::builder()
30 .data(&dataset)
31 .theta("direction")
32 .r("speed")
33 .mode(Mode::Markers)
34 .color(Rgb(65, 105, 225))
35 .shape(Shape::Circle)
36 .size(10)
37 .plot_title(Text::from("Wind Speed by Direction").font("Arial").size(20))
38 .build()
39 .plot();
40}
41
42fn styled_scatter_polar() {
43 // Create sample data - radar chart style
44 let categories = vec![0., 72., 144., 216., 288., 360.];
45 let performance = vec![8.0, 6.5, 7.0, 9.0, 5.5, 8.0];
46
47 let dataset = DataFrame::new(vec![
48 Column::new("category".into(), categories),
49 Column::new("performance".into(), performance),
50 ])
51 .unwrap();
52
53 ScatterPolar::builder()
54 .data(&dataset)
55 .theta("category")
56 .r("performance")
57 .mode(Mode::LinesMarkers)
58 .color(Rgb(255, 0, 0))
59 .shape(Shape::Diamond)
60 .line(Line::Solid)
61 .width(3.0)
62 .size(12)
63 .opacity(0.8)
64 .plot_title(
65 Text::from("Performance Radar Chart")
66 .font("Arial")
67 .size(22)
68 .x(0.5),
69 )
70 .build()
71 .plot();
72}
73
74fn grouped_scatter_polar() {
75 let dataset = LazyCsvReader::new(PlPath::new("data/product_comparison_polar.csv"))
76 .finish()
77 .unwrap()
78 .collect()
79 .unwrap();
80
81 ScatterPolar::builder()
82 .data(&dataset)
83 .theta("angle")
84 .r("score")
85 .group("product")
86 .mode(Mode::LinesMarkers)
87 .colors(vec![Rgb(255, 99, 71), Rgb(60, 179, 113)])
88 .shapes(vec![Shape::Circle, Shape::Square])
89 .lines(vec![Line::Solid, Line::Dash])
90 .width(2.5)
91 .size(8)
92 .plot_title(Text::from("Product Comparison").font("Arial").size(24))
93 .legend_title(Text::from("Products").font("Arial").size(14))
94 .legend(&Legend::new().x(0.85).y(0.95))
95 .build()
96 .plot();
97}
98
99fn filled_scatter_polar() {
100 // Create sample data - filled area chart
101 let angles: Vec<f64> = (0..=360).step_by(10).map(|x| x as f64).collect();
102 let radii: Vec<f64> = angles
103 .iter()
104 .map(|&angle| 5.0 + 3.0 * (angle * std::f64::consts::PI / 180.0).sin())
105 .collect();
106
107 let dataset = DataFrame::new(vec![
108 Column::new("angle".into(), angles),
109 Column::new("radius".into(), radii),
110 ])
111 .unwrap();
112
113 ScatterPolar::builder()
114 .data(&dataset)
115 .theta("angle")
116 .r("radius")
117 .mode(Mode::Lines)
118 .fill(Fill::ToSelf)
119 .color(Rgb(135, 206, 250))
120 .line(Line::Solid)
121 .width(2.0)
122 .opacity(0.6)
123 .plot_title(Text::from("Filled Polar Area Chart").font("Arial").size(20))
124 .build()
125 .plot();
126}More examples
examples/faceting.rs (line 562)
549fn scatterpolar_example() {
550 let dataset = CsvReadOptions::default()
551 .with_has_header(true)
552 .try_into_reader_with_file_path(Some("data/wind_patterns.csv".into()))
553 .unwrap()
554 .finish()
555 .unwrap();
556
557 let facet_config = FacetConfig::new()
558 .highlight_facet(true)
559 .unhighlighted_color(Rgb(220, 220, 220))
560 .cols(3);
561
562 ScatterPolar::builder()
563 .data(&dataset)
564 .theta("angle")
565 .r("speed")
566 .group("time")
567 .facet("season")
568 .facet_config(&facet_config)
569 .plot_title(Text::from("Wind Patterns by Season and Time of Day"))
570 .mode(Mode::LinesMarkers)
571 .opacity(0.7)
572 .size(7)
573 .width(2.5)
574 .colors(vec![Rgb(255, 105, 180), Rgb(30, 144, 255)])
575 .shapes(vec![Shape::Circle, Shape::Diamond])
576 .lines(vec![Line::Solid, Line::DashDot])
577 .legend_title("time of day")
578 .build()
579 .plot();
580}Trait Implementations§
Source§impl Clone for ScatterPolar
impl Clone for ScatterPolar
Source§fn clone(&self) -> ScatterPolar
fn clone(&self) -> ScatterPolar
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 moreSource§impl Serialize for ScatterPolar
impl Serialize for ScatterPolar
impl PlotHelper for ScatterPolar
Auto Trait Implementations§
impl Freeze for ScatterPolar
impl !RefUnwindSafe for ScatterPolar
impl !Send for ScatterPolar
impl !Sync for ScatterPolar
impl Unpin for ScatterPolar
impl !UnwindSafe for ScatterPolar
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