Community Internet Intensity Map#
M 4.7 - 1 km NW of Montagano, Italy#
import pandas as pd
from lets_plot import *
from lets_plot.geo_data import *
The geodata is provided by © OpenStreetMap contributors and is made available here under the Open Database License (ODbL).
LetsPlot.setup_html()
df = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/italy_cdi.csv")\
[["CDI", "No. of responses", "Latitude", "Longitude"]]
df.columns = ["CDI", "number_of_responses", "lat", "lon"]
print(df.shape)
df.head()
(27, 4)
| CDI | number_of_responses | lat | lon | |
|---|---|---|---|---|
| 0 | 3.1 | 1 | 42.37 | 14.07 |
| 1 | 2.2 | 1 | 42.25 | 14.37 |
| 2 | 2.0 | 1 | 42.20 | 14.21 |
| 3 | 3.1 | 1 | 42.22 | 14.28 |
| 4 | 3.4 | 4 | 42.46 | 14.21 |
gdf = geocode_counties().scope("Italy").inc_res(4).get_boundaries()
print(gdf.shape)
gdf.head()
(101, 3)
| county | found name | geometry | |
|---|---|---|---|
| 0 | Agrigento | Agrigento | MULTIPOLYGON (((12.53115 35.52931, 12.61914 35... |
| 1 | Siracusa | Siracusa | MULTIPOLYGON (((14.79537 37.13149, 14.81807 37... |
| 2 | Ragusa | Ragusa | MULTIPOLYGON (((14.37601 36.96449, 14.33723 37... |
| 3 | Trapani | Trapani | MULTIPOLYGON (((11.93565 36.83208, 11.93996 36... |
| 4 | Caltanissetta | Caltanissetta | MULTIPOLYGON (((13.77712 37.70153, 13.77603 37... |
p = ggplot(df) + \
geom_polygon(map=gdf, color="black", fill="white") + \
coord_map(xlim=[12, 16], ylim=[40, 43]) + \
theme_classic() + \
ggsize(640, 480)
p + geom_point(aes(x="lon", y="lat", fill="CDI", size="number_of_responses"), \
stroke=1, shape=21, color="#800026") + \
scale_size(range=[4, 16], guide='none') + \
scale_fill_brewer(type='seq', palette="YlOrRd") + \
ggtitle("Community decimal intensity") + \
theme_void()
p + geom_bin2d(aes(x="lon", y="lat", weight="number_of_responses", fill="..count.."), \
binwidth=[.5, .5], alpha=.75) + \
scale_fill_brewer(type='seq', palette="YlGnBu") + \
ggtitle("Number of responses") + \
theme_void()
p + geom_density2d(aes(x="lon", y="lat", weight="number_of_responses", color="..level.."), size=1) + \
scale_color_brewer(type='seq', palette="YlGnBu") + \
ggtitle("Distribution of responses") + \
theme_void()