Skip to main content

ScatterPolar

Struct ScatterPolar 

Source
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

BackendSupported
PlotlyYes
Plotters

§Arguments

  • data - A reference to the DataFrame containing 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 comparator fn(&str, &str) -> std::cmp::Ordering to 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 a FacetConfig struct for customizing facet behavior (grid dimensions, scales, gaps, etc.).
  • mode - An optional Mode specifying the drawing mode (lines, markers, or both). Defaults to markers.
  • opacity - An optional f64 value specifying the opacity of the plot elements (range: 0.0 to 1.0).
  • fill - An optional Fill type specifying how to fill the area under the trace.
  • size - An optional usize specifying the size of the markers.
  • color - An optional Rgb value specifying the color of the markers. This is used when group is not specified.
  • colors - An optional vector of Rgb values specifying the colors for the markers. This is used when group is specified to differentiate between groups.
  • shape - An optional Shape specifying the shape of the markers. This is used when group is not specified.
  • shapes - An optional vector of Shape values specifying multiple shapes for the markers when plotting multiple groups.
  • width - An optional f64 specifying the width of the lines.
  • line - An optional LineStyle specifying the style of the line (e.g., solid, dashed).
  • lines - An optional vector of LineStyle enums specifying the styles of lines for multiple traces.
  • plot_title - An optional Text struct specifying the title of the plot.
  • legend_title - An optional Text struct specifying the title of the legend.
  • legend - An optional reference to a Legend struct 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();

Example

Implementations§

Source§

impl ScatterPolar

Source

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
Hide additional 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

Source

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>

Source

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

Source§

fn clone(&self) -> ScatterPolar

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Plot for ScatterPolar

Source§

fn ir_traces(&self) -> &[TraceIR]

Source§

fn ir_layout(&self) -> &LayoutIR

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Key for T
where T: Clone,

Source§

fn align() -> usize

The alignment necessary for the key. Must return a power of two.
Source§

fn size(&self) -> usize

The size of the key in bytes.
Source§

unsafe fn init(&self, ptr: *mut u8)

Initialize the key in the given memory location. Read more
Source§

unsafe fn get<'a>(ptr: *const u8) -> &'a T

Get a reference to the key from the given memory location. Read more
Source§

unsafe fn drop_in_place(ptr: *mut u8)

Drop the key in place. Read more
Source§

impl<T> PlotlyExt for T
where T: Plot,

Source§

fn plot(&self)

Source§

fn write_html(&self, path: impl Into<String>)

Source§

fn to_json(&self) -> Result<String, Error>

Source§

fn to_html(&self) -> String

Source§

fn to_inline_html(&self, plot_div_id: Option<&str>) -> String

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> PlanCallbackArgs for T

Source§

impl<T> PlanCallbackOut for T