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.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 polars::prelude::*;
use plotlars::{Legend, Line, Mode, Plot, Rgb, ScatterPolar, Shape, Text};
// Create sample data - comparing two products across multiple metrics
let angles = vec![
0., 60., 120., 180., 240., 300., 360., // Product A
0., 60., 120., 180., 240., 300., 360., // Product B
];
let values = vec![
7.0, 8.5, 6.0, 5.5, 9.0, 8.0, 7.0, // Product A values
6.0, 7.0, 8.0, 9.0, 6.5, 7.5, 6.0, // Product B values
];
let products = vec![
"Product A", "Product A", "Product A", "Product A",
"Product A", "Product A", "Product A",
"Product B", "Product B", "Product B", "Product B",
"Product B", "Product B", "Product B",
];
let dataset = DataFrame::new(vec![
Column::new("angle".into(), angles),
Column::new("score".into(), values),
Column::new("product".into(), products),
])
.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("Product Comparison").font("Arial").size(24))
.legend_title(Text::from("Products").font("Arial").size(14))
.legend(&Legend::new().x(0.65).y(0.75))
.build()
.plot();
Implementations§
Source§impl ScatterPolar
impl ScatterPolar
Sourcepub fn builder<'f1, 'f2, 'f3, 'f4, 'f5>() -> ScatterPolarBuilder<'f1, 'f2, 'f3, 'f4, 'f5>
pub fn builder<'f1, 'f2, 'f3, 'f4, 'f5>() -> ScatterPolarBuilder<'f1, 'f2, 'f3, 'f4, 'f5>
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 // Create sample data - comparing two products across multiple metrics
76 let angles = vec![
77 0., 60., 120., 180., 240., 300., 360., // Product A
78 0., 60., 120., 180., 240., 300., 360., // Product B
79 ];
80 let values = vec![
81 7.0, 8.5, 6.0, 5.5, 9.0, 8.0, 7.0, // Product A values
82 6.0, 7.0, 8.0, 9.0, 6.5, 7.5, 6.0, // Product B values
83 ];
84 let products = vec![
85 "Product A",
86 "Product A",
87 "Product A",
88 "Product A",
89 "Product A",
90 "Product A",
91 "Product A",
92 "Product B",
93 "Product B",
94 "Product B",
95 "Product B",
96 "Product B",
97 "Product B",
98 "Product B",
99 ];
100
101 let dataset = DataFrame::new(vec![
102 Column::new("angle".into(), angles),
103 Column::new("score".into(), values),
104 Column::new("product".into(), products),
105 ])
106 .unwrap();
107
108 ScatterPolar::builder()
109 .data(&dataset)
110 .theta("angle")
111 .r("score")
112 .group("product")
113 .mode(Mode::LinesMarkers)
114 .colors(vec![
115 Rgb(255, 99, 71), // Tomato red
116 Rgb(60, 179, 113), // Medium sea green
117 ])
118 .shapes(vec![Shape::Circle, Shape::Square])
119 .lines(vec![Line::Solid, Line::Dash])
120 .width(2.5)
121 .size(8)
122 .plot_title(Text::from("Product Comparison").font("Arial").size(24))
123 .legend_title(Text::from("Products").font("Arial").size(14))
124 .legend(&Legend::new().x(0.85).y(0.95))
125 .build()
126 .plot();
127}
128
129fn filled_scatter_polar() {
130 // Create sample data - filled area chart
131 let angles: Vec<f64> = (0..=360).step_by(10).map(|x| x as f64).collect();
132 let radii: Vec<f64> = angles
133 .iter()
134 .map(|&angle| 5.0 + 3.0 * (angle * std::f64::consts::PI / 180.0).sin())
135 .collect();
136
137 let dataset = DataFrame::new(vec![
138 Column::new("angle".into(), angles),
139 Column::new("radius".into(), radii),
140 ])
141 .unwrap();
142
143 ScatterPolar::builder()
144 .data(&dataset)
145 .theta("angle")
146 .r("radius")
147 .mode(Mode::Lines)
148 .fill(Fill::ToSelf)
149 .color(Rgb(135, 206, 250))
150 .line(Line::Solid)
151 .width(2.0)
152 .opacity(0.6)
153 .plot_title(Text::from("Filled Polar Area Chart").font("Arial").size(20))
154 .build()
155 .plot();
156}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 PlotHelper for ScatterPolar
impl PlotHelper for ScatterPolar
fn get_layout(&self) -> &LayoutPlotly
fn get_traces(&self) -> &Vec<Box<dyn Trace + 'static>>
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