{ "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Unnamed: 0namelinkcoutry_idlatitudelongitudetext
00Algiers/wiki/Algiers136.7763893.058611— with nearly 3 million inhabitants, Algiers ...
11Annaba/wiki/Annaba136.9000007.766667— a town with 200,000 inhabitants in the east...
22Batna/wiki/Batna135.5500006.166667NaN
33Bechar/wiki/Bechar131.633333-2.200000— small city in the Sahara, not far from the ...
44Constantine/wiki/Constantine136.3650006.614722- Algeria's 3rd largest city with a canyon go...
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Unnamed: 0namelinkcoutry_idlatitudelongitudetext
10440Prague/wiki/Prague14450.08333314.416667() — the capital and largest city of the Czec...
10451Brno/wiki/Brno14449.20000016.616667— the largest city in Moravia and its former ...
10462České Budějovice/wiki/%C4%8Cesk%C3%A9_Bud%C4%9Bjovice14448.97472214.474722– attractive large city in South Bohemia
10473Český Krumlov/wiki/%C4%8Cesk%C3%BD_Krumlov14448.81666714.316667— beautiful old town in South Bohemia with th...
10484Karlovy Vary/wiki/Karlovy_Vary14450.23333312.866667() — historic (and biggest Czech) spa resort,...
10495Kutná Hora/wiki/Kutn%C3%A1_Hora14449.95000015.266667— historical town with famous Saint Barbara c...
10506Olomouc/wiki/Olomouc14449.60000017.250000( or ) — riverside university town with a tho...
10517Ostrava/wiki/Ostrava14449.83555618.292500— a vibrant local subculture and long history...
10528Pilsen/wiki/Pilsen14449.74750013.377500() — home of the original Pilsner Urquell bee...
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idcountryfound namecentroidpositionlimit
051684CzechCzech Republic[15.5282667270321, 49.8037022352219][12.0905895531178, 48.5518079996109, 18.859253...[12.0905895531178, 48.5518079996109, 18.859253...
\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 }