1use plotlars::{Mode, Plot, Rgb, ScatterGeo, Shape, Text};
2use polars::prelude::*;
3
4fn main() {
5 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 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 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 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}