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 theDataFrame
containing 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 optionalf64
value specifying the opacity of the plot markers (range: 0.0 to 1.0).size
- An optionalusize
specifying the size of the markers.color
- An optionalRgb
value specifying the color of the markers. This is used whengroup
is not specified.colors
- An optional vector ofRgb
values specifying the colors for the markers. This is used whengroup
is specified to differentiate between groups.shape
- An optionalShape
specifying the shape of the markers. This is used whengroup
is not specified.shapes
- An optional vector ofShape
values specifying multiple shapes for the markers when plotting multiple groups.plot_title
- An optionalText
struct specifying the title of the plot.x_title
- An optionalText
struct specifying the title of the x-axis.y_title
- An optionalText
struct specifying the title of the y-axis.legend_title
- An optionalText
struct specifying the title of the legend.x_axis
- An optional reference to anAxis
struct for customizing the x-axis.y_axis
- An optional reference to anAxis
struct for customizing the y-axis.legend
- An optional reference to aLegend
struct for customizing the legend of the plot (e.g., positioning, font, etc.).
§Example
use plotlars::{Axis, Legend, Plot, Rgb, ScatterPlot, Shape, Text, TickDirection};
let dataset = LazyCsvReader::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
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