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.
§Backend Support
| Backend | Supported |
|---|---|
| Plotly | Yes |
| Plotters | – |
§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/plotly_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 = CsvReader::new("data/product_comparison_polar.csv")
82 .finish()
83 .unwrap();
84
85 ScatterPolar::builder()
86 .data(&dataset)
87 .theta("angle")
88 .r("score")
89 .group("product")
90 .mode(Mode::LinesMarkers)
91 .colors(vec![Rgb(255, 99, 71), Rgb(60, 179, 113)])
92 .shapes(vec![Shape::Circle, Shape::Square])
93 .lines(vec![Line::Solid, Line::Dash])
94 .width(2.5)
95 .size(8)
96 .plot_title(Text::from("Product Comparison").font("Arial").size(24))
97 .legend_title(Text::from("Products").font("Arial").size(14))
98 .legend(&Legend::new().x(0.85).y(0.95))
99 .build()
100 .plot();
101}
102
103fn filled_scatter_polar() {
104 // Create sample data - filled area chart
105 let angles: Vec<f64> = (0..=360).step_by(10).map(|x| x as f64).collect();
106 let radii: Vec<f64> = angles
107 .iter()
108 .map(|&angle| 5.0 + 3.0 * (angle * std::f64::consts::PI / 180.0).sin())
109 .collect();
110
111 let dataset = DataFrame::new(
112 angles.len(),
113 vec![
114 Column::new("angle".into(), angles),
115 Column::new("radius".into(), radii),
116 ],
117 )
118 .unwrap();
119
120 ScatterPolar::builder()
121 .data(&dataset)
122 .theta("angle")
123 .r("radius")
124 .mode(Mode::Lines)
125 .fill(Fill::ToSelf)
126 .color(Rgb(135, 206, 250))
127 .line(Line::Solid)
128 .width(2.0)
129 .opacity(0.6)
130 .plot_title(Text::from("Filled Polar Area Chart").font("Arial").size(20))
131 .build()
132 .plot();
133}More examples
examples/plotly_faceting.rs (line 513)
505fn scatterpolar_example() {
506 let dataset = CsvReader::new("data/wind_patterns.csv").finish().unwrap();
507
508 let facet_config = FacetConfig::new()
509 .highlight_facet(true)
510 .unhighlighted_color(Rgb(220, 220, 220))
511 .cols(3);
512
513 ScatterPolar::builder()
514 .data(&dataset)
515 .theta("angle")
516 .r("speed")
517 .group("time")
518 .facet("season")
519 .facet_config(&facet_config)
520 .plot_title(Text::from("Wind Patterns by Season and Time of Day"))
521 .mode(Mode::LinesMarkers)
522 .opacity(0.7)
523 .size(7)
524 .width(2.5)
525 .colors(vec![Rgb(255, 105, 180), Rgb(30, 144, 255)])
526 .shapes(vec![Shape::Circle, Shape::Diamond])
527 .lines(vec![Line::Solid, Line::DashDot])
528 .legend_title("time of day")
529 .build()
530 .plot();
531}examples/plotly_subplot_grid.rs (line 283)
241fn mixed_grid_example() {
242 // 2D cartesian scatter (baseline)
243 let penguins = CsvReader::new("data/penguins.csv")
244 .finish()
245 .unwrap()
246 .lazy()
247 .select([
248 col("species"),
249 col("bill_length_mm"),
250 col("flipper_length_mm"),
251 col("body_mass_g"),
252 ])
253 .collect()
254 .unwrap();
255
256 let scatter_2d = ScatterPlot::builder()
257 .data(&penguins)
258 .x("bill_length_mm")
259 .y("flipper_length_mm")
260 .group("species")
261 .opacity(0.65)
262 .size(10)
263 .plot_title(Text::from("Penguins 2D").y(1.3))
264 .build();
265
266 // 3D scene subplot
267 let scatter_3d = Scatter3dPlot::builder()
268 .data(&penguins)
269 .x("bill_length_mm")
270 .y("flipper_length_mm")
271 .z("body_mass_g")
272 .group("species")
273 .opacity(0.35)
274 .size(6)
275 .plot_title(Text::from("Penguins 3D").y(1.45))
276 .build();
277
278 // Polar subplot
279 let polar_df = CsvReader::new("data/product_comparison_polar.csv")
280 .finish()
281 .unwrap();
282
283 let polar = ScatterPolar::builder()
284 .data(&polar_df)
285 .theta("angle")
286 .r("score")
287 .group("product")
288 .mode(Mode::LinesMarkers)
289 .size(10)
290 .plot_title(Text::from("Product Comparison (Polar)").y(1.5).x(0.72))
291 .legend(&Legend::new().x(0.8))
292 .build();
293
294 // Domain-based subplot (Sankey)
295 let sankey_df = CsvReader::new("data/energy_transition.csv")
296 .finish()
297 .unwrap();
298
299 let sankey = SankeyDiagram::builder()
300 .data(&sankey_df)
301 .sources("source")
302 .targets("target")
303 .values("value")
304 .orientation(Orientation::Horizontal)
305 .arrangement(Arrangement::Freeform)
306 .plot_title(Text::from("Energy Flow").y(1.2))
307 .build();
308
309 // Mapbox subplot
310 let map_df = CsvReader::new("data/cities.csv").finish().unwrap();
311
312 let scatter_map = ScatterMap::builder()
313 .data(&map_df)
314 .latitude("latitude")
315 .longitude("longitude")
316 .group("city")
317 .zoom(4)
318 .center([50.0, 5.0])
319 .opacity(0.8)
320 .plot_title(Text::from("Cities (Mapbox)").y(1.2))
321 .build();
322
323 // Geo subplot
324 let geo_df = CsvReader::new("data/world_cities.csv").finish().unwrap();
325
326 let scatter_geo = ScatterGeo::builder()
327 .data(&geo_df)
328 .lat("lat")
329 .lon("lon")
330 .group("continent")
331 .mode(Mode::Markers)
332 .size(10)
333 .color(Rgb(255, 140, 0))
334 .shape(Shape::Circle)
335 .plot_title(Text::from("Global Cities (Geo)").x(0.65).y(1.2))
336 .legend(&Legend::new().x(0.8))
337 .build();
338
339 SubplotGrid::regular()
340 .plots(vec![
341 &scatter_2d,
342 &scatter_3d,
343 &polar,
344 &sankey,
345 &scatter_map,
346 &scatter_geo,
347 ])
348 .rows(2)
349 .cols(3)
350 .h_gap(0.12)
351 .v_gap(0.22)
352 .title(
353 Text::from("Mixed Subplot Grid")
354 .size(16)
355 .font("Arial Black")
356 .y(0.95),
357 )
358 .build()
359 .plot();
360}Source§impl ScatterPolar
impl ScatterPolar
pub fn try_new( data: &DataFrame, theta: &str, r: &str, group: Option<&str>, sort_groups_by: Option<fn(&str, &str) -> Ordering>, facet: Option<&str>, facet_config: Option<&FacetConfig>, mode: Option<Mode>, opacity: Option<f64>, fill: Option<Fill>, size: Option<usize>, color: Option<Rgb>, colors: Option<Vec<Rgb>>, shape: Option<Shape>, shapes: Option<Vec<Shape>>, width: Option<f64>, line: Option<Line>, lines: Option<Vec<Line>>, plot_title: Option<Text>, legend_title: Option<Text>, legend: Option<&Legend>, ) -> Result<ScatterPolar, PlotlarsError>
pub fn try_builder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7>() -> ScatterPolarTryBuilder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7>
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 moreAuto Trait Implementations§
impl Freeze for ScatterPolar
impl RefUnwindSafe for ScatterPolar
impl Send for ScatterPolar
impl Sync for ScatterPolar
impl Unpin for ScatterPolar
impl UnsafeUnpin 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