Fancy line plots#

huracanpy.plot.fancyline allows you to plot a line with variable attributes (color, linewidth, transparency, linestyle). This is useful for showing a track and an attribute of that track on the same map. Below is an example of setting each of these variables using the track wind speed. The different options can also be combined

[1]:
import matplotlib.pyplot as plt
from cartopy.crs import EqualEarth

import huracanpy
from huracanpy.plot import fancyline


# Load in a single track from example data
tracks = huracanpy.load(huracanpy.example_csv_file)
track = tracks.groupby("track_id")[0]
[2]:
# Set up a figure with a cartopy projection
ax = plt.axes(projection=EqualEarth())

# Show 10m wind speed with a colourscale
lc = fancyline(
    track.lon,
    track.lat,
    track.wind10,
    vmin=10,
    vmax=25,
    ax=ax,
)

plt.colorbar(lc, extend="both")
ax.coastlines()
ax.gridlines(draw_labels=["left", "bottom"])
[2]:
<cartopy.mpl.gridliner.Gridliner at 0x797f1c0fe4e0>
/home/docs/checkouts/readthedocs.org/user_builds/huracanpy/envs/stable/lib/python3.12/site-packages/cartopy/io/__init__.py:242: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/50m_physical/ne_50m_coastline.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
../_images/examples_fancy_line_plot_2_2.png
[3]:
# Set up a figure with a cartopy projection
ax = plt.axes(projection=EqualEarth())

# Show 10m wind speed with linewidth
fancyline(
    track.lon,
    track.lat,
    linewidths=track.wind10,
    wmin=10,
    wmax=25,
    wrange=(1, 10),
)
ax.coastlines()
ax.gridlines(draw_labels=["left", "bottom"])
[3]:
<cartopy.mpl.gridliner.Gridliner at 0x797f1beea4e0>
../_images/examples_fancy_line_plot_3_1.png
[4]:
# Show 10m wind speed with alpha (transparency)
# Example with other arguments as single values for all lines

# Set up a figure with a cartopy projection
ax = plt.axes(projection=EqualEarth())

fancyline(
    track.lon,
    track.lat,
    alphas=track.wind10,
    amin=10,
    amax=25,
    arange=(0.5, 1),
    colors="k",
    linewidths=3,
    ax=ax,
)
ax.coastlines()
ax.gridlines(draw_labels=["left", "bottom"])
[4]:
<cartopy.mpl.gridliner.Gridliner at 0x797f1bf576e0>
../_images/examples_fancy_line_plot_4_1.png
[5]:
# Use the linestyle as categorical whether 10m wind is greater than a threshold
linestyles = ["--" if x < 20 else "-" for x in track.wind10]

ax = plt.axes(projection=EqualEarth())
fancyline(track.lon, track.lat, linestyles=linestyles, ax=ax)
ax.coastlines()
ax.gridlines(draw_labels=["left", "bottom"])
[5]:
<cartopy.mpl.gridliner.Gridliner at 0x797f1be186b0>
../_images/examples_fancy_line_plot_5_1.png