# Path ¶

Title
Path Element
Dependencies
Matplotlib
Backends
Matplotlib
Bokeh
In [1]:
import numpy as np
import holoviews as hv
hv.extension('matplotlib')


A  Path  object is actually a collection of lines, which are all plotted with the same style. Unlike  Curve  where the y-axis is the dependent variable, a  Path  consists of lines connecting arbitrary points in two-dimensional space as is not expected to be a function.

In [2]:
%%opts Path (color='black' linewidth=4)
lin = np.linspace(-np.pi,np.pi,300)

def lissajous(t, a,b, delta):
return (np.sin(a * t + delta), np.sin(b * t))

hv.Path(lissajous(np.linspace(-np.pi, np.pi, 1000),3,5,np.pi/2))

Out[2]:

Unlike  Curve  as single  Path  element can contain multiple lines that are disconnected from each other which will all be plotted in the same style. Only by overlaying multiple  Path  objects do you iterate through the defined color cycle (or any other style options that have been defined). A  Path  is often useful to draw arbitrary annotations on top of an existing plot.

A  Path  Element accepts multiple formats for specifying the paths, the simplest of which is passing a list of  Nx2  arrays of the x- and y-coordinates, alternative we can pass lists of coordinates. In this example we will create some coordinates representing rectangles and ellipses annotating an  RGB  image:

In [3]:
%%opts Path (linewidth=4)
angle = np.linspace(0, 2*np.pi, 100)
baby = list(zip(0.15*np.sin(angle),  0.2*np.cos(angle)-0.2))

adultR = [(0.25, 0.45), (0.35,0.35), (0.25, 0.25), (0.15, 0.35), (0.25, 0.45)]
adultL = [(-0.3, 0.4), (-0.3, 0.3), (-0.2, 0.3), (-0.2, 0.4),(-0.3, 0.4)]

scene * hv.Path([adultL, adultR, baby]) * hv.Path([baby])

Out[3]:

A  Path  can also be used as a means to display a number of lines with the same sampling along the x-axis at once. If we initialize the  Path  with a tuple of x-coordinates and stacked y-coordinates, we can quickly view a number of lines at once. Here we will generate a number of random traces each slightly offset along the y-axis:

In [4]:
%%opts Path [fig_size=400 aspect=3]
N, NLINES = 100, 10
hv.Path((np.arange(N), np.random.rand(N, NLINES) + np.arange(NLINES)[np.newaxis, :])) *\
hv.Path((np.arange(N), np.random.rand(N, NLINES) + np.arange(NLINES)[np.newaxis, :]))

Out[4]: