ScatterGeo

Struct ScatterGeo 

Source
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 the DataFrame containing 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 optional Mode specifying 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.
  • opacity - An optional f64 value specifying the opacity of the plot elements (range: 0.0 to 1.0).
  • size - An optional usize specifying the size of the markers.
  • color - An optional Rgb value specifying the color of the markers. This is used when group is not specified.
  • colors - An optional vector of Rgb values specifying the colors for the markers. This is used when group is specified.
  • shape - An optional Shape specifying the shape of the markers. This is used when group is not specified.
  • shapes - An optional vector of Shape values specifying multiple shapes for the markers when plotting multiple groups.
  • line_width - An optional f64 value specifying the width of the lines (when mode includes lines).
  • line_color - An optional Rgb value specifying the color of the lines.
  • plot_title - An optional Text struct specifying the title of the plot.
  • legend_title - An optional Text struct specifying the title of the legend.
  • legend - An optional reference to a Legend struct 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();

Example

Implementations§

Source§

impl ScatterGeo

Source

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

Source§

fn clone(&self) -> ScatterGeo

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Serialize for ScatterGeo

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Key for T
where T: Clone,

Source§

fn align() -> usize

The alignment necessary for the key. Must return a power of two.
Source§

fn size(&self) -> usize

The size of the key in bytes.
Source§

unsafe fn init(&self, ptr: *mut u8)

Initialize the key in the given memory location. Read more
Source§

unsafe fn get<'a>(ptr: *const u8) -> &'a T

Get a reference to the key from the given memory location. Read more
Source§

unsafe fn drop_in_place(ptr: *mut u8)

Drop the key in place. Read more
Source§

impl<T> Plot for T
where T: PlotHelper + Serialize + Clone,

Source§

fn plot(&self)

Source§

fn write_html(&self, path: impl Into<String>)

Source§

fn to_json(&self) -> Result<String, Error>

Source§

fn to_html(&self) -> String

Source§

fn to_inline_html(&self, plot_div_id: Option<&str>) -> String

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> PlanCallbackArgs for T

Source§

impl<T> PlanCallbackOut for T