{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Map of Kotlin Island with Inset\n", "\n", "Kotlin Island is situated in the Gulf of Finland and is one of the districts of the city of Saint Petersburg (Russia)." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:05:28.694126Z", "iopub.status.busy": "2026-01-27T17:05:28.694024Z", "iopub.status.idle": "2026-01-27T17:05:28.731773Z", "shell.execute_reply": "2026-01-27T17:05:28.731276Z" } }, "outputs": [], "source": [ "import geopandas as gpd\n", "from shapely.geometry import box\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:05:28.732758Z", "iopub.status.busy": "2026-01-27T17:05:28.732656Z", "iopub.status.idle": "2026-01-27T17:05:28.734638Z", "shell.execute_reply": "2026-01-27T17:05:28.734351Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### All Districts of St.Petersburg" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:05:28.747827Z", "iopub.status.busy": "2026-01-27T17:05:28.747751Z", "iopub.status.idle": "2026-01-27T17:05:29.430598Z", "shell.execute_reply": "2026-01-27T17:05:29.430120Z" } }, "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", "
osm_idgeometry
01115082MULTIPOLYGON (((29.54289 60.04227, 29.54305 60...
11114193MULTIPOLYGON (((30.25023 59.90129, 30.25112 59...
21114252MULTIPOLYGON (((30.18468 59.95472, 30.18449 59...
\n", "
" ], "text/plain": [ " osm_id geometry\n", "0 1115082 MULTIPOLYGON (((29.54289 60.04227, 29.54305 60...\n", "1 1114193 MULTIPOLYGON (((30.25023 59.90129, 30.25112 59...\n", "2 1114252 MULTIPOLYGON (((30.18468 59.95472, 30.18449 59..." ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# The districts boundaries.\n", "districts_gdf = gpd.read_file(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/spb_districts.geojson\")\n", "districts_gdf.head(3)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:05:29.431768Z", "iopub.status.busy": "2026-01-27T17:05:29.431693Z", "iopub.status.idle": "2026-01-27T17:05:29.433446Z", "shell.execute_reply": "2026-01-27T17:05:29.433028Z" } }, "outputs": [], "source": [ "# Kotlin Island bounding box.\n", "kotlin_bbox = [29.63, 59.965, 29.815, 60.035]\n", "kotlin_rect = dict(zip(['xmin', 'ymin', 'xmax', 'ymax'], kotlin_bbox))\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:05:29.434492Z", "iopub.status.busy": "2026-01-27T17:05:29.434397Z", "iopub.status.idle": "2026-01-27T17:05:29.480341Z", "shell.execute_reply": "2026-01-27T17:05:29.480011Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p_districts = (ggplot()\n", " + geom_polygon(map=districts_gdf, color='#a1d99b', fill='#f7fcf5')\n", " + geom_rect(**kotlin_rect, color='red', alpha=0)\n", " + geom_text(label='Saint Petersburg', x=30.334445, y=59.934294, size=6)\n", " + theme_void() + theme(plot_inset=0, plot_background=element_rect(size=1))\n", ")\n", "\n", "p_districts + coord_map()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Detailed Map of Kotlin Island" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:05:29.482398Z", "iopub.status.busy": "2026-01-27T17:05:29.482300Z", "iopub.status.idle": "2026-01-27T17:05:29.860556Z", "shell.execute_reply": "2026-01-27T17:05:29.859964Z" } }, "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", "
nametypegeometry
0Kronstadt Naval CathedralchurchPOINT (29.77745 59.99174)
1Kronstadt History MuseummuseumPOINT (29.79132 59.98678)
2Kronstadt Naval MuseummuseumPOINT (29.76342 59.99611)
\n", "
" ], "text/plain": [ " name type geometry\n", "0 Kronstadt Naval Cathedral church POINT (29.77745 59.99174)\n", "1 Kronstadt History Museum museum POINT (29.79132 59.98678)\n", "2 Kronstadt Naval Museum museum POINT (29.76342 59.99611)" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Tourist attractions with coordinates.\n", "places_gdf = gpd.read_file(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/kotlin_places.geojson\")\n", "places_gdf.head(3)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:05:29.861945Z", "iopub.status.busy": "2026-01-27T17:05:29.861818Z", "iopub.status.idle": "2026-01-27T17:05:29.906840Z", "shell.execute_reply": "2026-01-27T17:05:29.906376Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p_kotlin_isl = (ggplot()\n", " # Zoom-in the map. \n", " + coord_cartesian(xlim=kotlin_bbox[0::2], ylim=kotlin_bbox[1::2])\n", " + geom_polygon(map=districts_gdf, color='#31a354', fill='#e5f5e0')\n", " \n", " # Add the points of interest. \n", " + geom_point(aes(color='type', shape='type'), data=places_gdf, size=5)\n", " + geom_text(aes(label='name'), data=places_gdf, hjust='right', nudge_x=-5, nudge_unit='size')\n", "\n", " # Add annotation texts. \n", " + geom_text(label='Kotlin Isl.', x=29.725, y=60.011, color='#31a354', size=13, fontface='italic')\n", " + geom_text(label='Gulf of Finland', x=29.665, y=60.002, color='#578bcc', size=11, fontface='italic')\n", " \n", " + theme_void() + theme(\n", " plot_background=element_rect(fill='#F0F7FE', size=1),\n", " plot_inset=0,\n", " legend_title='blank',\n", " legend_position=[.1, .12],\n", " legend_background='blank'\n", " )\n", ") \n", "p_kotlin_isl" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Combining Both Plots in One Figure" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:05:29.908725Z", "iopub.status.busy": "2026-01-27T17:05:29.908648Z", "iopub.status.idle": "2026-01-27T17:05:29.982301Z", "shell.execute_reply": "2026-01-27T17:05:29.982008Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(ggbunch([p_kotlin_isl, p_districts],\n", " regions=[\n", " (0, 0, 1, 1),\n", " (0.75, 0, 0.25, 0.37, -10, 10)\n", " ]) \n", " + ggtitle('Tourist Attractions on Kotlin Island')\n", " + theme(plot_title=element_text(hjust=0.5, face='bold', size=16))\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": 4 }