hvPlot.paths#
- hvPlot.paths(x=None, y=None, c=None, **kwds)[source]#
Plot one or more collection of lines.
Each path is a collection of independent x and y coordinates, represented from:
tabular data: 1 path
gridded data: 1 path
GeoPandas GeoDataFrame: as many paths as LineString/MultiLineString as geometries contained in the dtaset
Options like
color
orline_width
are vectorized, i.e. each sub-line of a path can be displayed separately based on another dimension. For example, each sub-line of a hurricane path can be plotted with a color based on the wind speed.- Parameters:
- **kwdsoptional
Additional keywords arguments are documented in Plotting Options. Run
hvplot.help('paths')
for the full method documentation.
- Returns:
holoviews.element.Path
/ Panel objectYou can print the object to study its composition and run:
import holoviews as hv hv.help(the_holoviews_object)
to learn more about its parameters and options.
References
Backend-specific styling options#
alpha, cmap, color, hover_alpha, hover_color, hover_line_alpha, hover_line_cap, hover_line_color, hover_line_dash, hover_line_dash_offset, hover_line_join, hover_line_width, line_alpha, line_cap, line_color, line_dash, line_dash_offset, line_join, line_width, muted, muted_alpha, muted_color, muted_line_alpha, muted_line_cap, muted_line_color, muted_line_dash, muted_line_dash_offset, muted_line_join, muted_line_width, nonselection_alpha, nonselection_color, nonselection_line_alpha, nonselection_line_cap, nonselection_line_color, nonselection_line_dash, nonselection_line_dash_offset, nonselection_line_join, nonselection_line_width, selection_alpha, selection_color, selection_line_alpha, selection_line_cap, selection_line_color, selection_line_dash, selection_line_dash_offset, selection_line_join, selection_line_width, visible
alpha, c, cmap, color, linestyle, linewidth, lw, visible
Examples#
Basic paths plot from a DataFrame#
A simple set of x/y coordinates is needed to generate a paths
plot. While looking similarly to the output of a line
plot, the object returned is a HoloViews Path Element whose key dimensions are 'x'
and 'y'
, while for a line
plot the returned object is a Curve Element with 'x'
as key dimension and 'y'
as value dimension. This models the independence between x and y, which is for example appropriate for representing a trajectory like a hurricane track.
import hvplot.pandas # noqa
import pandas as pd
df = pd.DataFrame({'x': [0, 1, 2, 3], 'y': [0, 0.75, 1.25, 1.5]})
df.hvplot.paths(x='x', y='y', aspect='equal')
Vectorize color
and line_width
#
This example sets color
and line_width
, both referencing the 't'
dimension of this dataset: color
with the 't'
string, and line_width
with a HoloViews dim
object hv.dim('t')**2
that squares each value of 't'
. Each sub-line of the path has its color and width computed from these expressions.
import holoviews as hv
import hvplot.pandas # noqa
import pandas as pd
df = pd.DataFrame({'x': list(range(10)), 'y': list(range(10)), 't': list(range(1, 11))})
df.hvplot.paths(
x='x', y='y', color='t', cmap='viridis',
line_width=hv.dim('t')**2, aspect='equal',
)
From a GeoPandas dataset#
The paths
method can be used directly from GeoPandas GeoDataFrame objects containing LineString
or MultiLineString
geometries.
import hvplot.pandas # noqa
import geopandas as gpd
from shapely.geometry import LineString
lines = [
LineString([(-112.048, 33.451), (-112.03, 33.451)]),
LineString([(-112.048, 33.459), (-112.03, 33.459)]),
LineString([(-112.048, 33.466), (-112.03, 33.466)]),
LineString([(-112.048, 33.44), (-112.048, 33.48)]),
LineString([(-112.03, 33.44), (-112.03, 33.48)]),
]
categories = ['residential', 'residential', 'residential', 'arterial', 'arterial']
gdf = gpd.GeoDataFrame({'category': categories}, geometry=lines, crs='EPSG:4326')
gdf.hvplot.paths(
color='category', cmap='category10',
line_width=3, tiles=True, tiles_opts=dict(alpha=0.5),
)
import hvplot.pandas # noqa
import geopandas as gpd
from shapely.geometry import LineString, MultiLineString
lines = [
MultiLineString([
LineString([(-112.048, 33.451), (-112.03, 33.451)]),
LineString([(-112.048, 33.459), (-112.03, 33.459)]),
LineString([(-112.048, 33.466), (-112.03, 33.466)]),
]),
MultiLineString([
LineString([(-112.048, 33.44), (-112.048, 33.48)]),
LineString([(-112.03, 33.44), (-112.03, 33.48)]),
]),
]
categories = ['residential', 'arterial']
gdf = gpd.GeoDataFrame({'category': categories}, geometry=lines, crs='EPSG:4326')
gdf.hvplot.paths(
color='category', cmap='category10',
line_width=3, tiles=True, tiles_opts=dict(alpha=0.5),
)
From a DataFrame containing geographic coordinates#
Example adapted from https://scitools.org.uk/cartopy/docs/latest/matplotlib/intro.html.
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.
import cartopy.crs as ccrs
import hvplot.pandas # noqa
import pandas as pd
df = pd.DataFrame({"city": ["NY", "Delhi"], "lon": [-75, 77.23], "lat": [43, 28.61]})
common_kwargs = dict(
x="lon",
y="lat",
geo=True,
project=True,
projection=ccrs.GOOGLE_MERCATOR,
global_extent=True
)
shortest_path = df.hvplot.paths(color="blue", crs=ccrs.Geodetic(), tiles=True, **common_kwargs)
straight_path = df.hvplot.paths(color="grey", line_dash="dashed", **common_kwargs)
shortest_path * straight_path
From an Xarray Dataset#
import hvplot.xarray # noqa
import numpy as np
import pandas as pd
import xarray as xr
time = pd.date_range("2025-09-01", periods=20, freq="6h")
lon = [-55.0]
lat = [16.0]
for _ in range(1, len(time)):
lon.append(lon[-1] - np.random.uniform(0.3, 1.0))
lat.append(lat[-1] + np.random.uniform(0.1, 0.5))
base_speed = np.linspace(40, 120, len(time))
noise = np.random.normal(0, 5, len(time))
wind_speed = base_speed + noise
ds = xr.Dataset(
data_vars={"wind_speed": (["time"], wind_speed)},
coords={
"time": time,
"lon": ("time", lon),
"lat": ("time", lat)
},
)
ds.hvplot.paths(
x='lon', y='lat', color='wind_speed',
hover_cols=['time'], line_width=5, tiles=True,
)