{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "54d23f3c-34cb-489a-b081-2c8b74b533b2", "metadata": {}, "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": [ "from lets_plot import *\n", "from lets_plot.geo_data import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "bf529b2d-1a39-46e8-9db7-d65d6f5efe15", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "markdown", "id": "61304554-1994-47b2-bf0c-8ca6ef3dab53", "metadata": {}, "source": [ "##### Utils" ] }, { "cell_type": "code", "execution_count": 3, "id": "e4610759-1fdd-413e-8add-63ed82990591", "metadata": {}, "outputs": [], "source": [ "# to set up a projection using a non-public parameter\n", "from lets_plot.plot.coord import _coord as coord\n", "\n", "p = ggplot() + xlim(-180, 180) + ylim(-90, 90) + theme(axis=element_blank())\n", "\n", "def dump_plot(plot):\n", " import json\n", " import clipboard\n", " from lets_plot._type_utils import standardize_dict\n", " \n", " plot_dict = standardize_dict(plot.as_dict())\n", " plot_json = json.dumps(plot_dict, indent=2)\n", "\n", " clipboard.copy('')\n", " clipboard.copy(str(plot_json))\n", "\n", " return plot" ] }, { "cell_type": "code", "execution_count": 4, "id": "b485c37a-d668-4c04-bd05-70726c095952", "metadata": {}, "outputs": [], "source": [ "world = geocode_countries().get_boundaries(3)" ] }, { "cell_type": "code", "execution_count": 5, "id": "e02c58f8-2874-4bef-bd9a-c5d691e90481", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def draw_world_map(proj):\n", " return p \\\n", " + geom_map(map=world, fill='#E0E0E0', color='#C0C0C0', size=0.5) \\\n", " + coord('map', projection=proj) \\\n", " + ggtitle(proj) \\\n", " + theme(panel_grid=element_blank())\n", " \n", "gggrid([\n", " draw_world_map('merkator'),\n", " draw_world_map('azimuthal'),\n", " draw_world_map('conic'),\n", "])" ] }, { "cell_type": "code", "execution_count": 6, "id": "469afa66-45f4-45ba-9afa-a8b75746ca2c", "metadata": {}, "outputs": [], "source": [ "from geopandas import GeoDataFrame\n", "from shapely.geometry import Point\n", "from shapely.geometry import MultiPolygon, Polygon, MultiLineString, LineString, LinearRing, Point, mapping\n", "\n", "graticule = GeoDataFrame(\n", " data = {\n", " 'coord': [\n", " LineString([(-180, 0), (0, 0), (0, 0), (180, 0)]),\n", "\n", " LineString([(-180, 30), (0, 30)]), LineString([(0, 30), (180, 30)]),\n", " LineString([(-180, -30), (0, -30)]), LineString([(0, -30), (180, -30)]),\n", " \n", " LineString([(-180, 60), (0, 60)]), LineString([(0, 60), (180, 60)]),\n", " LineString([(-180, -60), (0, -60)]), LineString([(0, -60), (180, -60)]),\n", " \n", " LineString([(-180, 90), (0, 90)]), LineString([(0, 90), (180, 90)]),\n", " LineString([(-180, -90), (0, -90)]), LineString([(0, -90), (180, -90)]),\n", " \n", " LineString([(0, -90), (0, 90)]),\n", " LineString([(30, -90), (30, 90)]),\n", " LineString([(60, -90), (60, 90)]),\n", " LineString([(90, -90), (90, 90)]),\n", " LineString([(120, -90), (120, 90)]),\n", " LineString([(150, -90), (150, 90)]),\n", " LineString([(180, -90), (180, 90)]),\n", " \n", " LineString([(-30, -90), (-30, 90)]),\n", " LineString([(-60, -90), (-60, 90)]),\n", " LineString([(-90, -90), (-90, 90)]),\n", " LineString([(-120, -90), (-120, 90)]),\n", " LineString([(-150, -90), (-150, 90)]),\n", " LineString([(-180, -90), (-180, 90)]),\n", " ]},\n", " geometry='coord'\n", ")\n", "\n", "def show_graticule(projection):\n", " return gggrid([\n", " p + geom_path() + coord('map', projection=projection) + ggtitle('Empty'),\n", " p + geom_path(map=graticule) + coord('map', projection=projection) + ggtitle('Graticule'),\n", " ])" ] }, { "cell_type": "markdown", "id": "1dcbac1d-19a1-4a3f-94d8-bf7584aa49cd", "metadata": {}, "source": [ "## Mercator" ] }, { "cell_type": "code", "execution_count": 7, "id": "782e4d80-65d8-42d7-a887-bb319bc5f6ce", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "show_graticule('mercator')" ] }, { "cell_type": "markdown", "id": "26dca88d-66d5-4e0c-9bf0-745e0d6045ec", "metadata": {}, "source": [ "## Azimuthal" ] }, { "cell_type": "code", "execution_count": 8, "id": "f0563dfc-42af-474a-8f04-eebfca4ebdd9", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "show_graticule('azimuthal')" ] }, { "cell_type": "markdown", "id": "7be9afb3-c752-4494-835e-b806eae904cf", "metadata": {}, "source": [ "## Conic" ] }, { "cell_type": "code", "execution_count": 9, "id": "a0e7602c-6bee-44fd-bba1-f0d7a103dc44", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "show_graticule('conic')" ] }, { "cell_type": "markdown", "id": "464b14b7-09ae-4b08-9598-5f8429fd1782", "metadata": {}, "source": [ "### Issues" ] }, { "cell_type": "markdown", "id": "98eabdbe-c12f-46c3-93ed-e2a76dffa164", "metadata": {}, "source": [ "Axis ticks and breaks looking strange" ] }, { "cell_type": "code", "execution_count": 10, "id": "334f8c9e-bbd0-4e63-8a29-f702b74e7cd6", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gggrid([\n", " draw_world_map('azimuthal') + theme_minimal2(),\n", " draw_world_map('conic') + theme_minimal2()\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.8.15" } }, "nbformat": 4, "nbformat_minor": 5 }