{ "cells": [ { "cell_type": "markdown", "id": "182ed456", "metadata": {}, "source": [ "# Param `geodesic` in `geom_segment()` and `geom_path()`\n", "\n", "With `geodesic=True` a segment will be transformed to a curve representing the shortest path between two points on the surface of Earth.\n", "\n", "Note that this parameter only works when functions `geom_path()` and `geom_segment()` are used in combination with `geom_livemap()`." ] }, { "cell_type": "code", "execution_count": 1, "id": "bf3b27bb", "metadata": { "execution": { "iopub.execute_input": "2024-08-23T10:39:30.670680Z", "iopub.status.busy": "2024-08-23T10:39:30.670591Z", "iopub.status.idle": "2024-08-23T10:39:30.991777Z", "shell.execute_reply": "2024-08-23T10:39:30.991318Z" } }, "outputs": [], "source": [ "import pandas as pd\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "3142c360", "metadata": { "execution": { "iopub.execute_input": "2024-08-23T10:39:30.993411Z", "iopub.status.busy": "2024-08-23T10:39:30.993301Z", "iopub.status.idle": "2024-08-23T10:39:30.995503Z", "shell.execute_reply": "2024-08-23T10:39:30.995263Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "fd755b60", "metadata": { "execution": { "iopub.execute_input": "2024-08-23T10:39:30.996513Z", "iopub.status.busy": "2024-08-23T10:39:30.996444Z", "iopub.status.idle": "2024-08-23T10:39:30.998001Z", "shell.execute_reply": "2024-08-23T10:39:30.997769Z" } }, "outputs": [], "source": [ "LetsPlot.set(maptiles_lets_plot(theme='dark'))" ] }, { "cell_type": "markdown", "id": "7920c2c6", "metadata": {}, "source": [ "#### By Default, a Segment on Map is a Straight Line\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "bd2aa153", "metadata": { "execution": { "iopub.execute_input": "2024-08-23T10:39:30.998949Z", "iopub.status.busy": "2024-08-23T10:39:30.998877Z", "iopub.status.idle": "2024-08-23T10:39:31.030325Z", "shell.execute_reply": "2024-08-23T10:39:31.029946Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot() + geom_livemap() + \\\n", " geom_segment(x=-122.25165, y=37.464958, xend=139.4130, yend=35.4122, color='white', size=1)" ] }, { "cell_type": "markdown", "id": "b6196efe", "metadata": {}, "source": [ "#### Segment with `geodesic=True`" ] }, { "cell_type": "markdown", "id": "329f021b", "metadata": {}, "source": [ "With `geodesic=True` a segment on map becomes an arc. " ] }, { "cell_type": "code", "execution_count": 5, "id": "1ba15925", "metadata": { "execution": { "iopub.execute_input": "2024-08-23T10:39:31.031677Z", "iopub.status.busy": "2024-08-23T10:39:31.031596Z", "iopub.status.idle": "2024-08-23T10:39:31.034533Z", "shell.execute_reply": "2024-08-23T10:39:31.034276Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot() + geom_livemap() + \\\n", " geom_segment(x=-122.25165, y=37.464958, xend=139.4130, yend=35.4122, geodesic=True, color='white', size=1)" ] }, { "cell_type": "markdown", "id": "cf51bf43", "metadata": {}, "source": [ "#### `geom_path()` with `geodesic=True`\n" ] }, { "cell_type": "code", "execution_count": 6, "id": "51a02aad", "metadata": { "execution": { "iopub.execute_input": "2024-08-23T10:39:31.035694Z", "iopub.status.busy": "2024-08-23T10:39:31.035620Z", "iopub.status.idle": "2024-08-23T10:39:31.039233Z", "shell.execute_reply": "2024-08-23T10:39:31.038989Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = {\n", " 'city': ['New York', 'San-Francisco', 'Tokyo'],\n", " 'lon': [-73.935242, -122.25165, 139.4130],\n", " 'lat': [40.730610, 37.464958, 35.4122],\n", "}\n", "ggplot(data) + \\\n", " geom_livemap() + \\\n", " geom_path(aes(x='lon', y='lat'), color='white', size=1, linetype=\"dotted\") + \\\n", " geom_path(aes(x='lon', y='lat'), geodesic=True, color='white', size=1)" ] } ], "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 }