pub struct ScatterPlot { /* private fields */ }Expand description
A structure representing a scatter plot.
The ScatterPlot struct facilitates the creation and customization of 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, opacity settings, and comprehensive layout customization
including titles, axes, and legends.
§Arguments
data- A reference to theDataFramecontaining the data to be plotted.x- A string slice specifying the column name to be used for the x-axis (independent variable).y- A string slice specifying the column name to be used for the y-axis (dependent variable).group- An optional string slice specifying the column name to be used for grouping data points.opacity- An optionalf64value specifying the opacity of the plot markers (range: 0.0 to 1.0).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.plot_title- An optionalTextstruct specifying the title of the plot.x_title- An optionalTextstruct specifying the title of the x-axis.y_title- An optionalTextstruct specifying the title of the y-axis.legend_title- An optionalTextstruct specifying the title of the legend.x_axis- An optional reference to anAxisstruct for customizing the x-axis.y_axis- An optional reference to anAxisstruct for customizing the y-axis.legend- An optional reference to aLegendstruct for customizing the legend of the plot (e.g., positioning, font, etc.).
§Example
use polars::prelude::*;
use plotlars::{Axis, Legend, Plot, Rgb, ScatterPlot, Shape, Text, TickDirection};
let dataset = LazyCsvReader::new(PlPath::new("data/penguins.csv"))
.finish()
.unwrap()
.select([
col("species"),
col("sex").alias("gender"),
col("flipper_length_mm").cast(DataType::Int16),
col("body_mass_g").cast(DataType::Int16),
])
.collect()
.unwrap();
let axis = Axis::new()
.show_line(true)
.tick_direction(TickDirection::OutSide)
.value_thousands(true);
ScatterPlot::builder()
.data(&dataset)
.x("body_mass_g")
.y("flipper_length_mm")
.group("species")
.opacity(0.5)
.size(12)
.colors(vec![
Rgb(178, 34, 34),
Rgb(65, 105, 225),
Rgb(255, 140, 0),
])
.shapes(vec![
Shape::Circle,
Shape::Square,
Shape::Diamond,
])
.plot_title(
Text::from("Scatter Plot")
.font("Arial")
.size(20)
.x(0.065)
)
.x_title("body mass (g)")
.y_title("flipper length (mm)")
.legend_title("species")
.x_axis(
&axis.clone()
.value_range(vec![2500.0, 6500.0])
)
.y_axis(
&axis.clone()
.value_range(vec![170.0, 240.0])
)
.legend(
&Legend::new()
.x(0.85)
.y(0.15)
)
.build()
.plot();
Implementations§
Source§impl ScatterPlot
impl ScatterPlot
Sourcepub fn builder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7>() -> ScatterPlotBuilder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7>
pub fn builder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7>() -> ScatterPlotBuilder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7>
Examples found in repository?
examples/scatterplot.rs (line 23)
5fn main() {
6 let dataset = LazyCsvReader::new(PlPath::new("data/penguins.csv"))
7 .finish()
8 .unwrap()
9 .select([
10 col("species"),
11 col("sex").alias("gender"),
12 col("flipper_length_mm").cast(DataType::Int16),
13 col("body_mass_g").cast(DataType::Int16),
14 ])
15 .collect()
16 .unwrap();
17
18 let axis = Axis::new()
19 .show_line(true)
20 .tick_direction(TickDirection::OutSide)
21 .value_thousands(true);
22
23 ScatterPlot::builder()
24 .data(&dataset)
25 .x("body_mass_g")
26 .y("flipper_length_mm")
27 .group("species")
28 .opacity(0.5)
29 .size(12)
30 .colors(vec![Rgb(178, 34, 34), Rgb(65, 105, 225), Rgb(255, 140, 0)])
31 .shapes(vec![Shape::Circle, Shape::Square, Shape::Diamond])
32 .plot_title(Text::from("Scatter Plot").font("Arial").size(20).x(0.065))
33 .x_title("body mass (g)")
34 .y_title("flipper length (mm)")
35 .legend_title("species")
36 .x_axis(&axis.clone().value_range(vec![2500.0, 6500.0]))
37 .y_axis(&axis.clone().value_range(vec![170.0, 240.0]))
38 .legend(&Legend::new().x(0.85).y(0.15))
39 .build()
40 .plot();
41}Trait Implementations§
Source§impl Clone for ScatterPlot
impl Clone for ScatterPlot
Source§fn clone(&self) -> ScatterPlot
fn clone(&self) -> ScatterPlot
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 ScatterPlot
impl !RefUnwindSafe for ScatterPlot
impl !Send for ScatterPlot
impl !Sync for ScatterPlot
impl Unpin for ScatterPlot
impl !UnwindSafe for ScatterPlot
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