{
"cells": [
{
"cell_type": "markdown",
"id": "59dbb64d",
"metadata": {},
"source": [
"# Community Internet Intensity Map\n",
"\n",
"### M 4.7 - 1 km NW of Montagano, Italy"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "de1ede5d",
"metadata": {
"execution": {
"iopub.execute_input": "2024-08-23T10:45:00.457514Z",
"iopub.status.busy": "2024-08-23T10:45:00.457432Z",
"iopub.status.idle": "2024-08-23T10:45:00.846514Z",
"shell.execute_reply": "2024-08-23T10:45:00.846032Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The geodata is provided by © OpenStreetMap contributors and is made available here under the Open Database License (ODbL).\n"
]
}
],
"source": [
"import pandas as pd\n",
"\n",
"from lets_plot import *\n",
"from lets_plot.geo_data import *"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "557239b6",
"metadata": {
"execution": {
"iopub.execute_input": "2024-08-23T10:45:00.847939Z",
"iopub.status.busy": "2024-08-23T10:45:00.847819Z",
"iopub.status.idle": "2024-08-23T10:45:00.850325Z",
"shell.execute_reply": "2024-08-23T10:45:00.850074Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"
\n",
" \n",
" "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"LetsPlot.setup_html()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "c84b62ae",
"metadata": {
"execution": {
"iopub.execute_input": "2024-08-23T10:45:00.851506Z",
"iopub.status.busy": "2024-08-23T10:45:00.851432Z",
"iopub.status.idle": "2024-08-23T10:45:01.268462Z",
"shell.execute_reply": "2024-08-23T10:45:01.268083Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(27, 4)\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" CDI | \n",
" number_of_responses | \n",
" lat | \n",
" lon | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 3.1 | \n",
" 1 | \n",
" 42.37 | \n",
" 14.07 | \n",
"
\n",
" \n",
" 1 | \n",
" 2.2 | \n",
" 1 | \n",
" 42.25 | \n",
" 14.37 | \n",
"
\n",
" \n",
" 2 | \n",
" 2.0 | \n",
" 1 | \n",
" 42.20 | \n",
" 14.21 | \n",
"
\n",
" \n",
" 3 | \n",
" 3.1 | \n",
" 1 | \n",
" 42.22 | \n",
" 14.28 | \n",
"
\n",
" \n",
" 4 | \n",
" 3.4 | \n",
" 4 | \n",
" 42.46 | \n",
" 14.21 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" CDI number_of_responses lat lon\n",
"0 3.1 1 42.37 14.07\n",
"1 2.2 1 42.25 14.37\n",
"2 2.0 1 42.20 14.21\n",
"3 3.1 1 42.22 14.28\n",
"4 3.4 4 42.46 14.21"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.read_csv(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/italy_cdi.csv\")\\\n",
" [[\"CDI\", \"No. of responses\", \"Latitude\", \"Longitude\"]]\n",
"df.columns = [\"CDI\", \"number_of_responses\", \"lat\", \"lon\"]\n",
"print(df.shape)\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "509a14cd",
"metadata": {
"execution": {
"iopub.execute_input": "2024-08-23T10:45:01.269657Z",
"iopub.status.busy": "2024-08-23T10:45:01.269585Z",
"iopub.status.idle": "2024-08-23T10:45:01.989457Z",
"shell.execute_reply": "2024-08-23T10:45:01.989027Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(101, 3)\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" county | \n",
" found name | \n",
" geometry | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" Agrigento | \n",
" Agrigento | \n",
" MULTIPOLYGON (((12.53115 35.52931, 12.61914 35... | \n",
"
\n",
" \n",
" 1 | \n",
" Siracusa | \n",
" Siracusa | \n",
" MULTIPOLYGON (((14.79537 37.13149, 14.81807 37... | \n",
"
\n",
" \n",
" 2 | \n",
" Ragusa | \n",
" Ragusa | \n",
" MULTIPOLYGON (((14.37601 36.96449, 14.33723 37... | \n",
"
\n",
" \n",
" 3 | \n",
" Trapani | \n",
" Trapani | \n",
" MULTIPOLYGON (((11.93565 36.83208, 11.93996 36... | \n",
"
\n",
" \n",
" 4 | \n",
" Caltanissetta | \n",
" Caltanissetta | \n",
" MULTIPOLYGON (((13.77712 37.70153, 13.77603 37... | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" county found name \\\n",
"0 Agrigento Agrigento \n",
"1 Siracusa Siracusa \n",
"2 Ragusa Ragusa \n",
"3 Trapani Trapani \n",
"4 Caltanissetta Caltanissetta \n",
"\n",
" geometry \n",
"0 MULTIPOLYGON (((12.53115 35.52931, 12.61914 35... \n",
"1 MULTIPOLYGON (((14.79537 37.13149, 14.81807 37... \n",
"2 MULTIPOLYGON (((14.37601 36.96449, 14.33723 37... \n",
"3 MULTIPOLYGON (((11.93565 36.83208, 11.93996 36... \n",
"4 MULTIPOLYGON (((13.77712 37.70153, 13.77603 37... "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gdf = geocode_counties().scope(\"Italy\").inc_res(4).get_boundaries()\n",
"print(gdf.shape)\n",
"gdf.head()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "7ba2ec2a",
"metadata": {
"execution": {
"iopub.execute_input": "2024-08-23T10:45:01.990787Z",
"iopub.status.busy": "2024-08-23T10:45:01.990704Z",
"iopub.status.idle": "2024-08-23T10:45:01.993504Z",
"shell.execute_reply": "2024-08-23T10:45:01.993232Z"
}
},
"outputs": [],
"source": [
"p = ggplot(df) + \\\n",
" geom_polygon(map=gdf, color=\"black\", fill=\"white\") + \\\n",
" coord_map(xlim=[12, 16], ylim=[40, 43]) + \\\n",
" theme_classic() + \\\n",
" ggsize(640, 480)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "5f9b7b31",
"metadata": {
"execution": {
"iopub.execute_input": "2024-08-23T10:45:01.994742Z",
"iopub.status.busy": "2024-08-23T10:45:01.994667Z",
"iopub.status.idle": "2024-08-23T10:45:02.046776Z",
"shell.execute_reply": "2024-08-23T10:45:02.046415Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" \n",
" "
],
"text/plain": [
""
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"p + geom_point(aes(x=\"lon\", y=\"lat\", fill=\"CDI\", size=\"number_of_responses\"), \\\n",
" stroke=1, shape=21, color=\"#800026\") + \\\n",
" scale_size(range=[4, 16], guide='none') + \\\n",
" scale_fill_brewer(type='seq', palette=\"YlOrRd\") + \\\n",
" ggtitle(\"Community decimal intensity\") + \\\n",
" theme_void()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "578c9b17",
"metadata": {
"execution": {
"iopub.execute_input": "2024-08-23T10:45:02.048117Z",
"iopub.status.busy": "2024-08-23T10:45:02.048043Z",
"iopub.status.idle": "2024-08-23T10:45:02.100443Z",
"shell.execute_reply": "2024-08-23T10:45:02.099639Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" \n",
" "
],
"text/plain": [
""
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"p + geom_bin2d(aes(x=\"lon\", y=\"lat\", weight=\"number_of_responses\", fill=\"..count..\"), \\\n",
" binwidth=[.5, .5], alpha=.75) + \\\n",
" scale_fill_brewer(type='seq', palette=\"YlGnBu\") + \\\n",
" ggtitle(\"Number of responses\") + \\\n",
" theme_void()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "209d3cfa-5a2d-4a26-b823-db1c95de42ea",
"metadata": {
"execution": {
"iopub.execute_input": "2024-08-23T10:45:02.101922Z",
"iopub.status.busy": "2024-08-23T10:45:02.101838Z",
"iopub.status.idle": "2024-08-23T10:45:02.180168Z",
"shell.execute_reply": "2024-08-23T10:45:02.179686Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" \n",
" "
],
"text/plain": [
""
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"p + geom_density2d(aes(x=\"lon\", y=\"lat\", weight=\"number_of_responses\", color=\"..level..\"), size=1) + \\\n",
" scale_color_brewer(type='seq', palette=\"YlGnBu\") + \\\n",
" ggtitle(\"Distribution of responses\") + \\\n",
" theme_void()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}