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.

§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.
  • 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 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();

Example

Implementations§

Source§

impl ScatterPolar

Source

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

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 Serialize for ScatterPolar

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> Plot for T
where T: PlotHelper + Serialize + Clone,

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> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

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> ErasedDestructor for T
where T: 'static,

Source§

impl<T> PlanCallbackArgs for T

Source§

impl<T> PlanCallbackOut for T