{ "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-04-17T07:34:36.616864Z", "iopub.status.busy": "2024-04-17T07:34:36.616785Z", "iopub.status.idle": "2024-04-17T07:34:36.938295Z", "shell.execute_reply": "2024-04-17T07:34:36.937831Z" } }, "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-04-17T07:34:36.939819Z", "iopub.status.busy": "2024-04-17T07:34:36.939679Z", "iopub.status.idle": "2024-04-17T07:34:36.941808Z", "shell.execute_reply": "2024-04-17T07:34:36.941637Z" } }, "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-04-17T07:34:36.942947Z", "iopub.status.busy": "2024-04-17T07:34:36.942791Z", "iopub.status.idle": "2024-04-17T07:34:36.944185Z", "shell.execute_reply": "2024-04-17T07:34:36.944006Z" } }, "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-04-17T07:34:36.945290Z", "iopub.status.busy": "2024-04-17T07:34:36.945152Z", "iopub.status.idle": "2024-04-17T07:34:36.977210Z", "shell.execute_reply": "2024-04-17T07:34:36.976926Z" } }, "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-04-17T07:34:36.978385Z", "iopub.status.busy": "2024-04-17T07:34:36.978303Z", "iopub.status.idle": "2024-04-17T07:34:36.980846Z", "shell.execute_reply": "2024-04-17T07:34:36.980669Z" } }, "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-04-17T07:34:36.981990Z", "iopub.status.busy": "2024-04-17T07:34:36.981865Z", "iopub.status.idle": "2024-04-17T07:34:36.984915Z", "shell.execute_reply": "2024-04-17T07:34:36.984737Z" } }, "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 }