{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "individual-occasions",
"metadata": {
"execution": {
"iopub.execute_input": "2024-04-17T07:38:22.121344Z",
"iopub.status.busy": "2024-04-17T07:38:22.121207Z",
"iopub.status.idle": "2024-04-17T07:38:22.466681Z",
"shell.execute_reply": "2024-04-17T07:38:22.466379Z"
}
},
"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"
]
},
{
"data": {
"text/html": [
"\n",
"
\n",
" \n",
" "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import pandas as pd\n",
"\n",
"from lets_plot.geo_data import *\n",
"from lets_plot import *\n",
"\n",
"LetsPlot.setup_html()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "copyrighted-corpus",
"metadata": {
"execution": {
"iopub.execute_input": "2024-04-17T07:38:22.467984Z",
"iopub.status.busy": "2024-04-17T07:38:22.467849Z",
"iopub.status.idle": "2024-04-17T07:38:22.871580Z",
"shell.execute_reply": "2024-04-17T07:38:22.871389Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Unnamed: 0 | \n",
" name | \n",
" link | \n",
" coutry_id | \n",
" latitude | \n",
" longitude | \n",
" text | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 0 | \n",
" Algiers | \n",
" /wiki/Algiers | \n",
" 1 | \n",
" 36.776389 | \n",
" 3.058611 | \n",
" — with nearly 3 million inhabitants, Algiers ... | \n",
"
\n",
" \n",
" 1 | \n",
" 1 | \n",
" Annaba | \n",
" /wiki/Annaba | \n",
" 1 | \n",
" 36.900000 | \n",
" 7.766667 | \n",
" — a town with 200,000 inhabitants in the east... | \n",
"
\n",
" \n",
" 2 | \n",
" 2 | \n",
" Batna | \n",
" /wiki/Batna | \n",
" 1 | \n",
" 35.550000 | \n",
" 6.166667 | \n",
" NaN | \n",
"
\n",
" \n",
" 3 | \n",
" 3 | \n",
" Bechar | \n",
" /wiki/Bechar | \n",
" 1 | \n",
" 31.633333 | \n",
" -2.200000 | \n",
" — small city in the Sahara, not far from the ... | \n",
"
\n",
" \n",
" 4 | \n",
" 4 | \n",
" Constantine | \n",
" /wiki/Constantine | \n",
" 1 | \n",
" 36.365000 | \n",
" 6.614722 | \n",
" - Algeria's 3rd largest city with a canyon go... | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Unnamed: 0 name link coutry_id latitude \\\n",
"0 0 Algiers /wiki/Algiers 1 36.776389 \n",
"1 1 Annaba /wiki/Annaba 1 36.900000 \n",
"2 2 Batna /wiki/Batna 1 35.550000 \n",
"3 3 Bechar /wiki/Bechar 1 31.633333 \n",
"4 4 Constantine /wiki/Constantine 1 36.365000 \n",
"\n",
" longitude text \n",
"0 3.058611 — with nearly 3 million inhabitants, Algiers ... \n",
"1 7.766667 — a town with 200,000 inhabitants in the east... \n",
"2 6.166667 NaN \n",
"3 -2.200000 — small city in the Sahara, not far from the ... \n",
"4 6.614722 - Algeria's 3rd largest city with a canyon go... "
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cities = pd.read_csv(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/cities.csv\")\n",
"cities.head()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "marked-antarctica",
"metadata": {
"execution": {
"iopub.execute_input": "2024-04-17T07:38:22.872793Z",
"iopub.status.busy": "2024-04-17T07:38:22.872713Z",
"iopub.status.idle": "2024-04-17T07:38:22.876623Z",
"shell.execute_reply": "2024-04-17T07:38:22.876421Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Unnamed: 0 | \n",
" name | \n",
" link | \n",
" coutry_id | \n",
" latitude | \n",
" longitude | \n",
" text | \n",
"
\n",
" \n",
" \n",
" \n",
" 1044 | \n",
" 0 | \n",
" Prague | \n",
" /wiki/Prague | \n",
" 144 | \n",
" 50.083333 | \n",
" 14.416667 | \n",
" () — the capital and largest city of the Czec... | \n",
"
\n",
" \n",
" 1045 | \n",
" 1 | \n",
" Brno | \n",
" /wiki/Brno | \n",
" 144 | \n",
" 49.200000 | \n",
" 16.616667 | \n",
" — the largest city in Moravia and its former ... | \n",
"
\n",
" \n",
" 1046 | \n",
" 2 | \n",
" České Budějovice | \n",
" /wiki/%C4%8Cesk%C3%A9_Bud%C4%9Bjovice | \n",
" 144 | \n",
" 48.974722 | \n",
" 14.474722 | \n",
" – attractive large city in South Bohemia | \n",
"
\n",
" \n",
" 1047 | \n",
" 3 | \n",
" Český Krumlov | \n",
" /wiki/%C4%8Cesk%C3%BD_Krumlov | \n",
" 144 | \n",
" 48.816667 | \n",
" 14.316667 | \n",
" — beautiful old town in South Bohemia with th... | \n",
"
\n",
" \n",
" 1048 | \n",
" 4 | \n",
" Karlovy Vary | \n",
" /wiki/Karlovy_Vary | \n",
" 144 | \n",
" 50.233333 | \n",
" 12.866667 | \n",
" () — historic (and biggest Czech) spa resort,... | \n",
"
\n",
" \n",
" 1049 | \n",
" 5 | \n",
" Kutná Hora | \n",
" /wiki/Kutn%C3%A1_Hora | \n",
" 144 | \n",
" 49.950000 | \n",
" 15.266667 | \n",
" — historical town with famous Saint Barbara c... | \n",
"
\n",
" \n",
" 1050 | \n",
" 6 | \n",
" Olomouc | \n",
" /wiki/Olomouc | \n",
" 144 | \n",
" 49.600000 | \n",
" 17.250000 | \n",
" ( or ) — riverside university town with a tho... | \n",
"
\n",
" \n",
" 1051 | \n",
" 7 | \n",
" Ostrava | \n",
" /wiki/Ostrava | \n",
" 144 | \n",
" 49.835556 | \n",
" 18.292500 | \n",
" — a vibrant local subculture and long history... | \n",
"
\n",
" \n",
" 1052 | \n",
" 8 | \n",
" Pilsen | \n",
" /wiki/Pilsen | \n",
" 144 | \n",
" 49.747500 | \n",
" 13.377500 | \n",
" () — home of the original Pilsner Urquell bee... | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Unnamed: 0 name link \\\n",
"1044 0 Prague /wiki/Prague \n",
"1045 1 Brno /wiki/Brno \n",
"1046 2 České Budějovice /wiki/%C4%8Cesk%C3%A9_Bud%C4%9Bjovice \n",
"1047 3 Český Krumlov /wiki/%C4%8Cesk%C3%BD_Krumlov \n",
"1048 4 Karlovy Vary /wiki/Karlovy_Vary \n",
"1049 5 Kutná Hora /wiki/Kutn%C3%A1_Hora \n",
"1050 6 Olomouc /wiki/Olomouc \n",
"1051 7 Ostrava /wiki/Ostrava \n",
"1052 8 Pilsen /wiki/Pilsen \n",
"\n",
" coutry_id latitude longitude \\\n",
"1044 144 50.083333 14.416667 \n",
"1045 144 49.200000 16.616667 \n",
"1046 144 48.974722 14.474722 \n",
"1047 144 48.816667 14.316667 \n",
"1048 144 50.233333 12.866667 \n",
"1049 144 49.950000 15.266667 \n",
"1050 144 49.600000 17.250000 \n",
"1051 144 49.835556 18.292500 \n",
"1052 144 49.747500 13.377500 \n",
"\n",
" text \n",
"1044 () — the capital and largest city of the Czec... \n",
"1045 — the largest city in Moravia and its former ... \n",
"1046 – attractive large city in South Bohemia \n",
"1047 — beautiful old town in South Bohemia with th... \n",
"1048 () — historic (and biggest Czech) spa resort,... \n",
"1049 — historical town with famous Saint Barbara c... \n",
"1050 ( or ) — riverside university town with a tho... \n",
"1051 — a vibrant local subculture and long history... \n",
"1052 () — home of the original Pilsner Urquell bee... "
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"czech_cities = cities.loc[cities['coutry_id'] == 144]\n",
"czech_cities"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "pacific-stick",
"metadata": {
"execution": {
"iopub.execute_input": "2024-04-17T07:38:22.877814Z",
"iopub.status.busy": "2024-04-17T07:38:22.877708Z",
"iopub.status.idle": "2024-04-17T07:38:23.086487Z",
"shell.execute_reply": "2024-04-17T07:38:23.086085Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" id | \n",
" country | \n",
" found name | \n",
" centroid | \n",
" position | \n",
" limit | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 51684 | \n",
" Czech | \n",
" Czech Republic | \n",
" [15.5282667270321, 49.8037022352219] | \n",
" [12.0905895531178, 48.5518079996109, 18.859253... | \n",
" [12.0905895531178, 48.5518079996109, 18.859253... | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" id country found name centroid \\\n",
"0 51684 Czech Czech Republic [15.5282667270321, 49.8037022352219] \n",
"\n",
" position \\\n",
"0 [12.0905895531178, 48.5518079996109, 18.859253... \n",
"\n",
" limit \n",
"0 [12.0905895531178, 48.5518079996109, 18.859253... "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"country_gcoder = geocode_countries(['Czech'])\n",
"country_gcoder.get_geocodes()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "lightweight-integration",
"metadata": {
"execution": {
"iopub.execute_input": "2024-04-17T07:38:23.087629Z",
"iopub.status.busy": "2024-04-17T07:38:23.087543Z",
"iopub.status.idle": "2024-04-17T07:38:23.293506Z",
"shell.execute_reply": "2024-04-17T07:38:23.293206Z"
}
},
"outputs": [
{
"data": {
"text/html": [
" \n",
" "
],
"text/plain": [
""
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Automatic word wrap:\n",
"# the value string is limited by the number of characters in it,\n",
"# and description will be split into multiple lines.\n",
"\n",
"(ggplot()\n",
" + geom_livemap(location=[15.78,49.35], zoom=6)\n",
" + geom_polygon(aes(fill='country'), \n",
" data=country_gcoder.inc_res(3).get_boundaries(), \n",
" alpha=.2)\n",
" + geom_point(aes('longitude', 'latitude', color='name'),\n",
" data=czech_cities,\n",
" size=4, \n",
" tooltips=layer_tooltips()\n",
" .title('@name')\n",
" .line('Longitude|@longitude')\n",
" .line('Latitude|@latitude')\n",
" .line('Description|@text'))\n",
" + theme(legend_position='none')\n",
")"
]
}
],
"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
}