pub struct ScatterGeo { /* private fields */ }Expand description
A structure representing a geographic scatter plot.
The ScatterGeo struct facilitates the creation and customization of geographic scatter plots
with various options for data selection, grouping, layout configuration, and aesthetic adjustments.
It supports plotting data points on a map using latitude and longitude coordinates, with customization
for markers, lines, text labels, and comprehensive layout options.
§Arguments
data- A reference to theDataFramecontaining the data to be plotted.lat- A string slice specifying the column name to be used for latitude coordinates.lon- A string slice specifying the column name to be used for longitude coordinates.mode- An optionalModespecifying the drawing mode (markers, lines, or both).text- An optional string slice specifying the column name to be used for text labels.group- An optional string slice specifying the column name to be used for grouping data points.sort_groups_by- Optional comparatorfn(&str, &str) -> std::cmp::Orderingto control group ordering. Groups are sorted lexically by default.opacity- An optionalf64value specifying the opacity of the plot elements (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.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.line_width- An optionalf64value specifying the width of the lines (when mode includes lines).line_color- An optionalRgbvalue specifying the color of the lines.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 of the plot.
§Example
use plotlars::{Plot, Rgb, ScatterGeo, Shape, Text, Mode};
use polars::prelude::*;
// Create sample data with cities and their coordinates
let data = df![
"city" => ["New York", "Los Angeles", "Chicago", "Houston", "Phoenix"],
"lat" => [40.7128, 34.0522, 41.8781, 29.7604, 33.4484],
"lon" => [-74.0060, -118.2437, -87.6298, -95.3698, -112.0740],
"population" => [8336817, 3979576, 2693976, 2320268, 1680992],
"region" => ["East", "West", "Central", "South", "West"]
].unwrap();
ScatterGeo::builder()
.data(&data)
.lat("lat")
.lon("lon")
.mode(Mode::Markers)
.text("city")
.group("region")
.size(15)
.colors(vec![
Rgb(255, 0, 0),
Rgb(0, 255, 0),
Rgb(0, 0, 255),
Rgb(255, 165, 0),
])
.plot_title(
Text::from("US Cities by Region")
.font("Arial")
.size(20)
)
.legend_title("Region")
.build()
.plot();
Implementations§
Source§impl ScatterGeo
impl ScatterGeo
Sourcepub fn builder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6>() -> ScatterGeoBuilder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6>
pub fn builder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6>() -> ScatterGeoBuilder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6>
Examples found in repository?
examples/scattergeo.rs (line 13)
4fn main() {
5 // Example 1: Basic ScatterGeo with markers only
6 let cities = df![
7 "city" => ["New York", "Los Angeles", "Chicago", "Houston", "Phoenix"],
8 "lat" => [40.7128, 34.0522, 41.8781, 29.7604, 33.4484],
9 "lon" => [-74.0060, -118.2437, -87.6298, -95.3698, -112.0740],
10 ]
11 .unwrap();
12
13 ScatterGeo::builder()
14 .data(&cities)
15 .lat("lat")
16 .lon("lon")
17 .text("city")
18 .plot_title(Text::from("US Major Cities").font("Arial").size(20))
19 .build()
20 .plot();
21
22 // Example 2: ScatterGeo with grouping by region
23 let cities_with_regions = df![
24 "city" => ["New York", "Los Angeles", "Chicago", "Houston", "Phoenix", "Philadelphia", "San Antonio", "San Diego", "Dallas", "San Jose"],
25 "lat" => [40.7128, 34.0522, 41.8781, 29.7604, 33.4484, 39.9526, 29.4241, 32.7157, 32.7767, 37.3382],
26 "lon" => [-74.0060, -118.2437, -87.6298, -95.3698, -112.0740, -75.1652, -98.4936, -117.1611, -96.7970, -121.8863],
27 "population" => [8336817, 3979576, 2693976, 2320268, 1680992, 1584064, 1547253, 1423851, 1343573, 1021795],
28 "region" => ["Northeast", "West", "Midwest", "South", "West", "Northeast", "South", "West", "South", "West"]
29 ]
30 .unwrap();
31
32 ScatterGeo::builder()
33 .data(&cities_with_regions)
34 .lat("lat")
35 .lon("lon")
36 .mode(Mode::Markers)
37 .text("city")
38 .group("region")
39 .size(20)
40 .colors(vec![
41 Rgb(255, 0, 0),
42 Rgb(0, 255, 0),
43 Rgb(0, 0, 255),
44 Rgb(255, 165, 0),
45 ])
46 .shapes(vec![
47 Shape::Circle,
48 Shape::Square,
49 Shape::Diamond,
50 Shape::Cross,
51 ])
52 .plot_title(
53 Text::from("US Cities by Region")
54 .font("Arial")
55 .size(24)
56 .x(0.5),
57 )
58 .legend_title(Text::from("Region").size(14))
59 .build()
60 .plot();
61
62 // Example 3: ScatterGeo with lines connecting cities (flight paths)
63 let flight_path = df![
64 "city" => ["New York", "Chicago", "Denver", "Los Angeles"],
65 "lat" => [40.7128, 41.8781, 39.7392, 34.0522],
66 "lon" => [-74.0060, -87.6298, -104.9903, -118.2437],
67 ]
68 .unwrap();
69
70 ScatterGeo::builder()
71 .data(&flight_path)
72 .lat("lat")
73 .lon("lon")
74 .mode(Mode::LinesMarkers)
75 .text("city")
76 .size(15)
77 .color(Rgb(0, 123, 255))
78 .line_width(2.0)
79 .line_color(Rgb(255, 123, 0))
80 .opacity(0.8)
81 .plot_title(Text::from("Flight Path: NY to LA").font("Arial").size(20))
82 .build()
83 .plot();
84
85 // Example 4: World cities with custom styling
86 let world_cities = df![
87 "city" => ["London", "Paris", "Tokyo", "Sydney", "Cairo", "Mumbai", "Beijing", "Rio de Janeiro", "Toronto"],
88 "lat" => [51.5074, 48.8566, 35.6762, -33.8688, 30.0444, 19.0760, 39.9042, -22.9068, 43.6532],
89 "lon" => [-0.1278, 2.3522, 139.6503, 151.2093, 31.2357, 72.8777, 116.4074, -43.1729, -79.3832],
90 "continent" => ["Europe", "Europe", "Asia", "Oceania", "Africa", "Asia", "Asia", "South America", "North America"],
91 "population_millions" => [9.0, 2.2, 13.9, 5.3, 9.5, 12.4, 21.5, 6.7, 2.9]
92 ]
93 .unwrap();
94
95 ScatterGeo::builder()
96 .data(&world_cities)
97 .lat("lat")
98 .lon("lon")
99 .mode(Mode::Markers)
100 .text("city")
101 .group("continent")
102 .size(25)
103 .opacity(0.7)
104 .colors(vec![
105 Rgb(255, 0, 0),
106 Rgb(0, 255, 0),
107 Rgb(0, 0, 255),
108 Rgb(255, 255, 0),
109 Rgb(255, 0, 255),
110 Rgb(0, 255, 255),
111 ])
112 .plot_title(
113 Text::from("Major World Cities by Continent")
114 .font("Arial")
115 .size(24),
116 )
117 .legend_title(Text::from("Continent").size(16))
118 .build()
119 .plot();
120}Trait Implementations§
Source§impl Clone for ScatterGeo
impl Clone for ScatterGeo
Source§fn clone(&self) -> ScatterGeo
fn clone(&self) -> ScatterGeo
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 PlotHelper for ScatterGeo
impl PlotHelper for ScatterGeo
fn get_layout(&self) -> &LayoutPlotly
fn get_traces(&self) -> &Vec<Box<dyn Trace + 'static>>
Auto Trait Implementations§
impl Freeze for ScatterGeo
impl !RefUnwindSafe for ScatterGeo
impl !Send for ScatterGeo
impl !Sync for ScatterGeo
impl Unpin for ScatterGeo
impl !UnwindSafe for ScatterGeo
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