pub struct Scatter3dPlot { /* private fields */ }Expand description
A structure representing a 3D scatter plot.
The Scatter3dPlot struct is designed to create and customize 3D scatter plots with options for data selection,
grouping, layout configuration, and aesthetic adjustments. It supports visual differentiation in data groups
through varied marker shapes, colors, sizes, opacity levels, and comprehensive layout customization, including
titles, axis labels, 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).z- A string slice specifying the column name to be used for the z-axis, adding a third dimension to the scatter plot.group- An optional string slice specifying the column name used for grouping data points by category.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.).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 for marker color whengroupis not specified.colors- An optional vector ofRgbvalues specifying colors for markers whengroupis specified, enhancing group distinction.shape- An optionalShapespecifying the shape of markers whengroupis not specified.shapes- An optional vector ofShapevalues defining multiple marker shapes for different groups.plot_title- An optionalTextstruct specifying the plot title.x_title- An optionalTextstruct for the x-axis title.y_title- An optionalTextstruct for the y-axis title.z_title- An optionalTextstruct for the z-axis title.legend_title- An optionalTextstruct specifying the legend title.x_axis- An optional reference to anAxisstruct for custom x-axis settings.y_axis- An optional reference to anAxisstruct for custom y-axis settings.z_axis- An optional reference to anAxisstruct for custom z-axis settings, adding depth perspective.legend- An optional reference to aLegendstruct for legend customization, including position and font settings.
§Example
use plotlars::{Legend, Plot, Rgb, Scatter3dPlot, Shape};
use polars::prelude::*;
let dataset = LazyCsvReader::new(PlRefPath::new("data/penguins.csv"))
.finish()
.unwrap()
.select([
col("species"),
col("sex").alias("gender"),
col("bill_length_mm").cast(DataType::Float32),
col("flipper_length_mm").cast(DataType::Int16),
col("body_mass_g").cast(DataType::Int16),
])
.collect()
.unwrap();
Scatter3dPlot::builder()
.data(&dataset)
.x("body_mass_g")
.y("flipper_length_mm")
.z("bill_length_mm")
.group("species")
.opacity(0.25)
.size(8)
.colors(vec![
Rgb(178, 34, 34),
Rgb(65, 105, 225),
Rgb(255, 140, 0),
])
.shapes(vec![
Shape::Circle,
Shape::Square,
Shape::Diamond,
])
.plot_title("Scatter Plot")
.legend(
&Legend::new()
.x(0.6)
)
.build()
.plot();
Implementations§
Source§impl Scatter3dPlot
impl Scatter3dPlot
Sourcepub fn builder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7, 'f8>() -> Scatter3dPlotBuilder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7, 'f8>
pub fn builder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7, 'f8>() -> Scatter3dPlotBuilder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7, 'f8>
Examples found in repository?
examples/scatter3dplot.rs (line 18)
4fn main() {
5 let dataset = LazyCsvReader::new(PlRefPath::new("data/penguins.csv"))
6 .finish()
7 .unwrap()
8 .select([
9 col("species"),
10 col("sex").alias("gender"),
11 col("bill_length_mm").cast(DataType::Float32),
12 col("flipper_length_mm").cast(DataType::Int16),
13 col("body_mass_g").cast(DataType::Int16),
14 ])
15 .collect()
16 .unwrap();
17
18 Scatter3dPlot::builder()
19 .data(&dataset)
20 .x("body_mass_g")
21 .y("flipper_length_mm")
22 .z("bill_length_mm")
23 .group("species")
24 .opacity(0.25)
25 .size(8)
26 .colors(vec![Rgb(178, 34, 34), Rgb(65, 105, 225), Rgb(255, 140, 0)])
27 .shapes(vec![Shape::Circle, Shape::Square, Shape::Diamond])
28 .plot_title("Scatter 3D Plot")
29 .legend(&Legend::new().x(0.6))
30 .build()
31 .plot();
32}More examples
examples/faceting.rs (line 537)
518fn scatter3d_example() {
519 let dataset = LazyCsvReader::new(PlRefPath::new("data/penguins.csv"))
520 .finish()
521 .unwrap()
522 .select([
523 col("species"),
524 col("sex").alias("gender"),
525 col("bill_length_mm").cast(DataType::Float32),
526 col("flipper_length_mm").cast(DataType::Int16),
527 col("body_mass_g").cast(DataType::Int16),
528 ])
529 .collect()
530 .unwrap();
531
532 let facet_config = FacetConfig::new()
533 .cols(3)
534 .highlight_facet(true)
535 .unhighlighted_color(Rgb(220, 220, 220));
536
537 Scatter3dPlot::builder()
538 .data(&dataset)
539 .x("body_mass_g")
540 .y("flipper_length_mm")
541 .z("bill_length_mm")
542 .facet("species")
543 .facet_config(&facet_config)
544 .opacity(0.6)
545 .size(6)
546 .colors(vec![Rgb(178, 34, 34), Rgb(65, 105, 225), Rgb(255, 140, 0)])
547 .plot_title("Penguin Morphological Traits - 3D Faceted Analysis")
548 .build()
549 .plot();
550}examples/subplot_grid.rs (line 276)
248fn mixed_grid_example() {
249 // 2D cartesian scatter (baseline)
250 let penguins = LazyCsvReader::new(PlRefPath::new("data/penguins.csv"))
251 .finish()
252 .unwrap()
253 .collect()
254 .unwrap()
255 .lazy()
256 .select([
257 col("species"),
258 col("bill_length_mm"),
259 col("flipper_length_mm"),
260 col("body_mass_g"),
261 ])
262 .collect()
263 .unwrap();
264
265 let scatter_2d = ScatterPlot::builder()
266 .data(&penguins)
267 .x("bill_length_mm")
268 .y("flipper_length_mm")
269 .group("species")
270 .opacity(0.65)
271 .size(10)
272 .plot_title(Text::from("Penguins 2D").y(1.3))
273 .build();
274
275 // 3D scene subplot
276 let scatter_3d = Scatter3dPlot::builder()
277 .data(&penguins)
278 .x("bill_length_mm")
279 .y("flipper_length_mm")
280 .z("body_mass_g")
281 .group("species")
282 .opacity(0.35)
283 .size(6)
284 .plot_title(Text::from("Penguins 3D").y(1.45))
285 .build();
286
287 // Polar subplot
288 let polar_df = LazyCsvReader::new(PlRefPath::new("data/product_comparison_polar.csv"))
289 .finish()
290 .unwrap()
291 .collect()
292 .unwrap();
293
294 let polar = ScatterPolar::builder()
295 .data(&polar_df)
296 .theta("angle")
297 .r("score")
298 .group("product")
299 .mode(Mode::LinesMarkers)
300 .size(10)
301 .plot_title(Text::from("Product Comparison (Polar)").y(1.5).x(0.72))
302 .legend(&Legend::new().x(0.8))
303 .build();
304
305 // Domain-based subplot (Sankey)
306 let sankey_df = LazyCsvReader::new(PlRefPath::new("data/energy_transition.csv"))
307 .finish()
308 .unwrap()
309 .collect()
310 .unwrap();
311
312 let sankey = SankeyDiagram::builder()
313 .data(&sankey_df)
314 .sources("source")
315 .targets("target")
316 .values("value")
317 .orientation(Orientation::Horizontal)
318 .arrangement(Arrangement::Freeform)
319 .plot_title(Text::from("Energy Flow").y(1.2))
320 .build();
321
322 // Mapbox subplot
323 let map_df = LazyCsvReader::new(PlRefPath::new("data/cities.csv"))
324 .finish()
325 .unwrap()
326 .collect()
327 .unwrap();
328
329 let scatter_map = ScatterMap::builder()
330 .data(&map_df)
331 .latitude("latitude")
332 .longitude("longitude")
333 .group("city")
334 .zoom(4)
335 .center([50.0, 5.0])
336 .opacity(0.8)
337 .plot_title(Text::from("Cities (Mapbox)").y(1.2))
338 .build();
339
340 // Geo subplot
341 let geo_df = LazyCsvReader::new(PlRefPath::new("data/world_cities.csv"))
342 .finish()
343 .unwrap()
344 .collect()
345 .unwrap();
346
347 let scatter_geo = ScatterGeo::builder()
348 .data(&geo_df)
349 .lat("lat")
350 .lon("lon")
351 .group("continent")
352 .mode(Mode::Markers)
353 .size(10)
354 .color(Rgb(255, 140, 0))
355 .shape(Shape::Circle)
356 .plot_title(Text::from("Global Cities (Geo)").x(0.65).y(1.2))
357 .legend(&Legend::new().x(0.8))
358 .build();
359
360 SubplotGrid::regular()
361 .plots(vec![
362 &scatter_2d,
363 &scatter_3d,
364 &polar,
365 &sankey,
366 &scatter_map,
367 &scatter_geo,
368 ])
369 .rows(2)
370 .cols(3)
371 .h_gap(0.12)
372 .v_gap(0.22)
373 .title(
374 Text::from("Mixed Subplot Grid")
375 .size(16)
376 .font("Arial bold")
377 .y(0.95),
378 )
379 .build()
380 .plot();
381}Trait Implementations§
Source§impl Clone for Scatter3dPlot
impl Clone for Scatter3dPlot
Source§fn clone(&self) -> Scatter3dPlot
fn clone(&self) -> Scatter3dPlot
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 moreSource§impl Serialize for Scatter3dPlot
impl Serialize for Scatter3dPlot
impl PlotHelper for Scatter3dPlot
Auto Trait Implementations§
impl Freeze for Scatter3dPlot
impl !RefUnwindSafe for Scatter3dPlot
impl !Send for Scatter3dPlot
impl !Sync for Scatter3dPlot
impl Unpin for Scatter3dPlot
impl !UnwindSafe for Scatter3dPlot
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