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.
§Backend Support
| Backend | Supported |
|---|---|
| Plotly | Yes |
| Plotters | – |
§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/plotly_scatter3dplot.rs (line 19)
4fn main() {
5 let dataset = CsvReader::new("data/penguins.csv")
6 .finish()
7 .unwrap()
8 .lazy()
9 .select([
10 col("species"),
11 col("sex").alias("gender"),
12 col("bill_length_mm").cast(DataType::Float32),
13 col("flipper_length_mm").cast(DataType::Int16),
14 col("body_mass_g").cast(DataType::Int16),
15 ])
16 .collect()
17 .unwrap();
18
19 Scatter3dPlot::builder()
20 .data(&dataset)
21 .x("body_mass_g")
22 .y("flipper_length_mm")
23 .z("bill_length_mm")
24 .group("species")
25 .opacity(0.25)
26 .size(8)
27 .colors(vec![Rgb(178, 34, 34), Rgb(65, 105, 225), Rgb(255, 140, 0)])
28 .shapes(vec![Shape::Circle, Shape::Square, Shape::Diamond])
29 .plot_title("Scatter 3D Plot")
30 .legend(&Legend::new().x(0.6))
31 .build()
32 .plot();
33}More examples
examples/plotly_faceting.rs (line 490)
470fn scatter3d_example() {
471 let dataset = CsvReader::new("data/penguins.csv")
472 .finish()
473 .unwrap()
474 .lazy()
475 .select([
476 col("species"),
477 col("sex").alias("gender"),
478 col("bill_length_mm").cast(DataType::Float32),
479 col("flipper_length_mm").cast(DataType::Int16),
480 col("body_mass_g").cast(DataType::Int16),
481 ])
482 .collect()
483 .unwrap();
484
485 let facet_config = FacetConfig::new()
486 .cols(3)
487 .highlight_facet(true)
488 .unhighlighted_color(Rgb(220, 220, 220));
489
490 Scatter3dPlot::builder()
491 .data(&dataset)
492 .x("body_mass_g")
493 .y("flipper_length_mm")
494 .z("bill_length_mm")
495 .facet("species")
496 .facet_config(&facet_config)
497 .opacity(0.6)
498 .size(6)
499 .colors(vec![Rgb(178, 34, 34), Rgb(65, 105, 225), Rgb(255, 140, 0)])
500 .plot_title("Penguin Morphological Traits - 3D Faceted Analysis")
501 .build()
502 .plot();
503}examples/plotly_subplot_grid.rs (line 267)
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 Scatter3dPlot
impl Scatter3dPlot
pub fn try_new( data: &DataFrame, x: &str, y: &str, z: &str, group: Option<&str>, sort_groups_by: Option<fn(&str, &str) -> Ordering>, facet: Option<&str>, facet_config: Option<&FacetConfig>, opacity: Option<f64>, size: Option<usize>, color: Option<Rgb>, colors: Option<Vec<Rgb>>, shape: Option<Shape>, shapes: Option<Vec<Shape>>, plot_title: Option<Text>, legend: Option<&Legend>, ) -> Result<Scatter3dPlot, PlotlarsError>
pub fn try_builder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7, 'f8>() -> Scatter3dPlotTryBuilder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7, 'f8>
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 (const: unstable) · 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 Scatter3dPlot
impl RefUnwindSafe for Scatter3dPlot
impl Send for Scatter3dPlot
impl Sync for Scatter3dPlot
impl Unpin for Scatter3dPlot
impl UnsafeUnpin 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