Skip to content

Commit

Permalink
add paths nb (#1354)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuang11 authored Jun 18, 2024
1 parent c37d795 commit 3699aeb
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions doc/reference/pandas/paths.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Paths"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import hvplot.pandas # noqa\n",
"import cartopy.crs as ccrs"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Paths are useful if you are plotting lines on a geographic map."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df = pd.DataFrame({\"city\": [\"NY\", \"Delhi\"], \"lon\": [-75, 77.23], \"lat\": [43, 28.61]})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Notice how the line in blue between New York and Delhi is not straight on a flat PlateCarree map, this is because the Geodetic coordinate system is a truly spherical coordinate system, where a line between two points is defined as the shortest path between those points on the globe rather than 2d Cartesian space."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"common_kwargs = dict(\n",
" x=\"lon\",\n",
" y=\"lat\",\n",
" geo=True,\n",
" project=True,\n",
" projection=ccrs.GOOGLE_MERCATOR,\n",
" global_extent=True\n",
")\n",
"shortest_path = df.hvplot.paths(color=\"blue\", crs=ccrs.Geodetic(), tiles=True, **common_kwargs)\n",
"straight_path = df.hvplot.paths(color=\"grey\", line_dash=\"dashed\", **common_kwargs)\n",
"labels = df.hvplot.labels(text_color=\"black\", text=\"city\", **common_kwargs)\n",
"shortest_path * straight_path * labels"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Example adapted from https://scitools.org.uk/cartopy/docs/latest/matplotlib/intro.html."
]
}
],
"metadata": {
"language_info": {
"name": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 3699aeb

Please sign in to comment.