pub struct ScatterMap { /* private fields */ }Expand description
A structure representing a scatter plot on a map.
The ScatterMap struct allows for visualizing geographical data points on an interactive map.
Each data point is defined by its latitude and longitude, with additional options for grouping,
coloring, size, opacity, and map configuration such as zoom level and center coordinates.
This struct is ideal for displaying spatial data distributions, such as city locations or geospatial datasets.
§Backend Support
| Backend | Supported |
|---|---|
| Plotly | Yes |
| Plotters | – |
§Arguments
data- A reference to theDataFramecontaining the data to be plotted.latitude- A string slice specifying the column name containing latitude values.longitude- A string slice specifying the column name containing longitude values.center- An optional array[f64; 2]specifying the initial center point of the map ([latitude, longitude]).zoom- An optionalu8specifying the initial zoom level of the map.group- An optional string slice specifying the column name for grouping data points (e.g., by city or category).sort_groups_by- Optional comparatorfn(&str, &str) -> std::cmp::Orderingto control group ordering. Groups are sorted lexically by default.opacity- An optionalf64value between0.0and1.0specifying the opacity of the points.size- An optionalusizespecifying the size of the scatter points.color- An optionalRgbvalue specifying the color of the points (if no grouping is applied).colors- An optional vector ofRgbvalues specifying colors for grouped points.shape- An optionalShapeenum specifying the marker shape for the points.shapes- An optional vector ofShapeenums specifying shapes for grouped points.plot_title- An optionalTextstruct specifying the title of the plot.legend_title- An optionalTextstruct specifying the title of the legend.legend- An optional reference to aLegendstruct for customizing the legend (e.g., positioning, font, etc.).
§Example
§Basic Scatter Map Plot
use plotlars::{Plot, ScatterMap, Text};
use polars::prelude::*;
let dataset = LazyCsvReader::new(PlRefPath::new("data/cities.csv"))
.finish()
.unwrap()
.collect()
.unwrap();
ScatterMap::builder()
.data(&dataset)
.latitude("latitude")
.longitude("longitude")
.center([48.856613, 2.352222])
.zoom(4)
.group("city")
.opacity(0.5)
.size(12)
.plot_title(
Text::from("Scatter Map")
.font("Arial")
.size(18)
)
.legend_title("cities")
.build()
.plot();
Implementations§
Source§impl ScatterMap
impl ScatterMap
Sourcepub fn builder<'f1, 'f2, 'f3, 'f4, 'f5>() -> ScatterMapBuilder<'f1, 'f2, 'f3, 'f4, 'f5>
pub fn builder<'f1, 'f2, 'f3, 'f4, 'f5>() -> ScatterMapBuilder<'f1, 'f2, 'f3, 'f4, 'f5>
Examples found in repository?
examples/plotly_scattermap.rs (line 6)
3fn main() {
4 let dataset = CsvReader::new("data/cities.csv").finish().unwrap();
5
6 ScatterMap::builder()
7 .data(&dataset)
8 .latitude("latitude")
9 .longitude("longitude")
10 .center([48.856613, 2.352222])
11 .zoom(4)
12 .group("city")
13 .opacity(0.5)
14 .size(12)
15 .plot_title(Text::from("Scatter Map").font("Arial").size(18))
16 .legend_title("cities")
17 .build()
18 .plot();
19}More examples
examples/plotly_subplot_grid.rs (line 312)
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 ScatterMap
impl ScatterMap
pub fn try_new( data: &DataFrame, latitude: &str, longitude: &str, center: Option<[f64; 2]>, zoom: Option<u8>, group: Option<&str>, sort_groups_by: Option<fn(&str, &str) -> Ordering>, 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_title: Option<Text>, legend: Option<&Legend>, ) -> Result<ScatterMap, PlotlarsError>
pub fn try_builder<'f1, 'f2, 'f3, 'f4, 'f5>() -> ScatterMapTryBuilder<'f1, 'f2, 'f3, 'f4, 'f5>
Trait Implementations§
Source§impl Clone for ScatterMap
impl Clone for ScatterMap
Source§fn clone(&self) -> ScatterMap
fn clone(&self) -> ScatterMap
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 ScatterMap
impl RefUnwindSafe for ScatterMap
impl Send for ScatterMap
impl Sync for ScatterMap
impl Unpin for ScatterMap
impl UnsafeUnpin for ScatterMap
impl UnwindSafe for ScatterMap
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