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(PlRefPath::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 32)
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(
24 directions.len(),
25 vec![
26 Column::new("direction".into(), directions),
27 Column::new("speed".into(), speeds),
28 ],
29 )
30 .unwrap();
31
32 ScatterPolar::builder()
33 .data(&dataset)
34 .theta("direction")
35 .r("speed")
36 .mode(Mode::Markers)
37 .color(Rgb(65, 105, 225))
38 .shape(Shape::Circle)
39 .size(10)
40 .plot_title(Text::from("Wind Speed by Direction").font("Arial").size(20))
41 .build()
42 .plot();
43}
44
45fn styled_scatter_polar() {
46 // Create sample data - radar chart style
47 let categories = vec![0., 72., 144., 216., 288., 360.];
48 let performance = vec![8.0, 6.5, 7.0, 9.0, 5.5, 8.0];
49
50 let dataset = DataFrame::new(
51 categories.len(),
52 vec![
53 Column::new("category".into(), categories),
54 Column::new("performance".into(), performance),
55 ],
56 )
57 .unwrap();
58
59 ScatterPolar::builder()
60 .data(&dataset)
61 .theta("category")
62 .r("performance")
63 .mode(Mode::LinesMarkers)
64 .color(Rgb(255, 0, 0))
65 .shape(Shape::Diamond)
66 .line(Line::Solid)
67 .width(3.0)
68 .size(12)
69 .opacity(0.8)
70 .plot_title(
71 Text::from("Performance Radar Chart")
72 .font("Arial")
73 .size(22)
74 .x(0.5),
75 )
76 .build()
77 .plot();
78}
79
80fn grouped_scatter_polar() {
81 let dataset = LazyCsvReader::new(PlRefPath::new("data/product_comparison_polar.csv"))
82 .finish()
83 .unwrap()
84 .collect()
85 .unwrap();
86
87 ScatterPolar::builder()
88 .data(&dataset)
89 .theta("angle")
90 .r("score")
91 .group("product")
92 .mode(Mode::LinesMarkers)
93 .colors(vec![Rgb(255, 99, 71), Rgb(60, 179, 113)])
94 .shapes(vec![Shape::Circle, Shape::Square])
95 .lines(vec![Line::Solid, Line::Dash])
96 .width(2.5)
97 .size(8)
98 .plot_title(Text::from("Product Comparison").font("Arial").size(24))
99 .legend_title(Text::from("Products").font("Arial").size(14))
100 .legend(&Legend::new().x(0.85).y(0.95))
101 .build()
102 .plot();
103}
104
105fn filled_scatter_polar() {
106 // Create sample data - filled area chart
107 let angles: Vec<f64> = (0..=360).step_by(10).map(|x| x as f64).collect();
108 let radii: Vec<f64> = angles
109 .iter()
110 .map(|&angle| 5.0 + 3.0 * (angle * std::f64::consts::PI / 180.0).sin())
111 .collect();
112
113 let dataset = DataFrame::new(
114 angles.len(),
115 vec![
116 Column::new("angle".into(), angles),
117 Column::new("radius".into(), radii),
118 ],
119 )
120 .unwrap();
121
122 ScatterPolar::builder()
123 .data(&dataset)
124 .theta("angle")
125 .r("radius")
126 .mode(Mode::Lines)
127 .fill(Fill::ToSelf)
128 .color(Rgb(135, 206, 250))
129 .line(Line::Solid)
130 .width(2.0)
131 .opacity(0.6)
132 .plot_title(Text::from("Filled Polar Area Chart").font("Arial").size(20))
133 .build()
134 .plot();
135}More examples
examples/faceting.rs (line 565)
552fn scatterpolar_example() {
553 let dataset = CsvReadOptions::default()
554 .with_has_header(true)
555 .try_into_reader_with_file_path(Some("data/wind_patterns.csv".into()))
556 .unwrap()
557 .finish()
558 .unwrap();
559
560 let facet_config = FacetConfig::new()
561 .highlight_facet(true)
562 .unhighlighted_color(Rgb(220, 220, 220))
563 .cols(3);
564
565 ScatterPolar::builder()
566 .data(&dataset)
567 .theta("angle")
568 .r("speed")
569 .group("time")
570 .facet("season")
571 .facet_config(&facet_config)
572 .plot_title(Text::from("Wind Patterns by Season and Time of Day"))
573 .mode(Mode::LinesMarkers)
574 .opacity(0.7)
575 .size(7)
576 .width(2.5)
577 .colors(vec![Rgb(255, 105, 180), Rgb(30, 144, 255)])
578 .shapes(vec![Shape::Circle, Shape::Diamond])
579 .lines(vec![Line::Solid, Line::DashDot])
580 .legend_title("time of day")
581 .build()
582 .plot();
583}examples/subplot_grid.rs (line 294)
248fn mixed_grid_example() {
249 // 2D cartesian scatter (baseline)
250 let penguins = LazyCsvReader::new(PlRefPath::new("data/penguins.csv"))
251 .finish()
252 .unwrap()
253 .collect()
254 .unwrap()
255 .lazy()
256 .select([
257 col("species"),
258 col("bill_length_mm"),
259 col("flipper_length_mm"),
260 col("body_mass_g"),
261 ])
262 .collect()
263 .unwrap();
264
265 let scatter_2d = ScatterPlot::builder()
266 .data(&penguins)
267 .x("bill_length_mm")
268 .y("flipper_length_mm")
269 .group("species")
270 .opacity(0.65)
271 .size(10)
272 .plot_title(Text::from("Penguins 2D").y(1.3))
273 .build();
274
275 // 3D scene subplot
276 let scatter_3d = Scatter3dPlot::builder()
277 .data(&penguins)
278 .x("bill_length_mm")
279 .y("flipper_length_mm")
280 .z("body_mass_g")
281 .group("species")
282 .opacity(0.35)
283 .size(6)
284 .plot_title(Text::from("Penguins 3D").y(1.45))
285 .build();
286
287 // Polar subplot
288 let polar_df = LazyCsvReader::new(PlRefPath::new("data/product_comparison_polar.csv"))
289 .finish()
290 .unwrap()
291 .collect()
292 .unwrap();
293
294 let polar = ScatterPolar::builder()
295 .data(&polar_df)
296 .theta("angle")
297 .r("score")
298 .group("product")
299 .mode(Mode::LinesMarkers)
300 .size(10)
301 .plot_title(Text::from("Product Comparison (Polar)").y(1.5).x(0.72))
302 .legend(&Legend::new().x(0.8))
303 .build();
304
305 // Domain-based subplot (Sankey)
306 let sankey_df = LazyCsvReader::new(PlRefPath::new("data/energy_transition.csv"))
307 .finish()
308 .unwrap()
309 .collect()
310 .unwrap();
311
312 let sankey = SankeyDiagram::builder()
313 .data(&sankey_df)
314 .sources("source")
315 .targets("target")
316 .values("value")
317 .orientation(Orientation::Horizontal)
318 .arrangement(Arrangement::Freeform)
319 .plot_title(Text::from("Energy Flow").y(1.2))
320 .build();
321
322 // Mapbox subplot
323 let map_df = LazyCsvReader::new(PlRefPath::new("data/cities.csv"))
324 .finish()
325 .unwrap()
326 .collect()
327 .unwrap();
328
329 let scatter_map = ScatterMap::builder()
330 .data(&map_df)
331 .latitude("latitude")
332 .longitude("longitude")
333 .group("city")
334 .zoom(4)
335 .center([50.0, 5.0])
336 .opacity(0.8)
337 .plot_title(Text::from("Cities (Mapbox)").y(1.2))
338 .build();
339
340 // Geo subplot
341 let geo_df = LazyCsvReader::new(PlRefPath::new("data/world_cities.csv"))
342 .finish()
343 .unwrap()
344 .collect()
345 .unwrap();
346
347 let scatter_geo = ScatterGeo::builder()
348 .data(&geo_df)
349 .lat("lat")
350 .lon("lon")
351 .group("continent")
352 .mode(Mode::Markers)
353 .size(10)
354 .color(Rgb(255, 140, 0))
355 .shape(Shape::Circle)
356 .plot_title(Text::from("Global Cities (Geo)").x(0.65).y(1.2))
357 .legend(&Legend::new().x(0.8))
358 .build();
359
360 SubplotGrid::regular()
361 .plots(vec![
362 &scatter_2d,
363 &scatter_3d,
364 &polar,
365 &sankey,
366 &scatter_map,
367 &scatter_geo,
368 ])
369 .rows(2)
370 .cols(3)
371 .h_gap(0.12)
372 .v_gap(0.22)
373 .title(
374 Text::from("Mixed Subplot Grid")
375 .size(16)
376 .font("Arial bold")
377 .y(0.95),
378 )
379 .build()
380 .plot();
381}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