{ "cells": [ { "cell_type": "markdown", "id": "434f933d-bea3-4a3b-9f89-4a4155818bb0", "metadata": {}, "source": [ "# Line Plot" ] }, { "cell_type": "code", "execution_count": null, "id": "d7edfab9-5c44-4f6a-a966-7cd7cc10676d", "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "from cartopy.crs import EqualEarth\n", "\n", "import huracanpy\n", "from huracanpy.plot import fancyline\n", "\n", "\n", "# Load in a single track from example data\n", "tracks = huracanpy.load(huracanpy.example_csv_file)\n", "track = tracks.groupby(\"track_id\")[0]" ] }, { "cell_type": "code", "execution_count": null, "id": "ec1fddb1-5c87-4a6f-a481-1a6283145243", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [ "nbsphinx-thumbnail" ] }, "outputs": [], "source": [ "# Set up a figure with a cartopy projection\n", "ax = plt.axes(projection=EqualEarth())\n", "\n", "# Show 10m wind speed with a colourscale\n", "lc = fancyline(\n", " track.lon,\n", " track.lat,\n", " track.wind10,\n", " vmin=10,\n", " vmax=25,\n", " ax=ax,\n", ")\n", "\n", "plt.colorbar(lc, extend=\"both\")\n", "ax.coastlines()\n", "ax.gridlines(draw_labels=[\"left\", \"bottom\"])" ] }, { "cell_type": "code", "execution_count": null, "id": "304cd531-cbe5-45fe-8e66-7ab6c8afa20a", "metadata": {}, "outputs": [], "source": [ "# Set up a figure with a cartopy projection\n", "ax = plt.axes(projection=EqualEarth())\n", "\n", "# Show 10m wind speed with linewidth\n", "fancyline(\n", " track.lon,\n", " track.lat,\n", " linewidths=track.wind10,\n", " wmin=10,\n", " wmax=25,\n", " wrange=(1, 10),\n", ")\n", "ax.coastlines()\n", "ax.gridlines(draw_labels=[\"left\", \"bottom\"])" ] }, { "cell_type": "code", "execution_count": null, "id": "a446aad3-77c1-4d5e-933d-ee32595d4b7b", "metadata": {}, "outputs": [], "source": [ "# Show 10m wind speed with alpha (transparency)\n", "# Example with other arguments as single values for all lines\n", "\n", "# Set up a figure with a cartopy projection\n", "ax = plt.axes(projection=EqualEarth())\n", "\n", "fancyline(\n", " track.lon,\n", " track.lat,\n", " alphas=track.wind10,\n", " amin=10,\n", " amax=25,\n", " arange=(0.5, 1),\n", " colors=\"k\",\n", " linewidths=3,\n", " ax=ax,\n", ")\n", "ax.coastlines()\n", "ax.gridlines(draw_labels=[\"left\", \"bottom\"])" ] }, { "cell_type": "code", "execution_count": null, "id": "c2e9e67b-0905-428a-bdd7-8b27edeb2d0d", "metadata": {}, "outputs": [], "source": [ "# Use the linestyle as categorical whether 10m wind is greater than a threshold\n", "linestyles = [\"--\" if x < 20 else \"-\" for x in track.wind10]\n", "\n", "ax = plt.axes(projection=EqualEarth())\n", "fancyline(track.lon, track.lat, linestyles=linestyles, ax=ax)\n", "ax.coastlines()\n", "ax.gridlines(draw_labels=[\"left\", \"bottom\"])" ] } ], "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.12.4" } }, "nbformat": 4, "nbformat_minor": 5 }