Contours Element
In [1]:
import numpy as np
import holoviews as hv

A Contours object is similar to a Path element but allows each individual path to be associated with one or more scalar values declared as value dimensions ( vdims ), which can be used to apply colormapping the Contours . Just like the Path element Contours will accept a list of arrays, dataframes, a dictionaries of columns (or any of the other literal formats including tuples of columns and lists of tuples). In order to efficiently represent the scalar values associated with each path the dictionary format is preferable since it can store the scalar values without expanding them into a whole column.

To see the effect we will create a number of concentric rings with increasing radii and define a colormap to apply color the circles:

In [2]:
def circle(radius):
    angles = np.linspace(0, 2*np.pi, 50)
    return {'x': radius*np.sin(angles), 'y': radius*np.cos(angles), 'radius': radius}

hv.Contours([circle(i) for i in np.linspace(0, 1, 10)], vdims='radius')

Often Contours will be directly computed from an underlying Image , which is made easy using the contours operation. The operation accepts an Image type as input and will return Contours containing iso-contours for each of the specified levels . We will declare an Image of sine rings and then compute Contours at 5 levels spaced linearly over the range of values in the Image:

In [3]:
%%opts Contours [colorbar=True] (cmap='fire')
x,y = np.mgrid[-50:51, -50:51] * 0.05
img = hv.Image(np.sin(x**2+y**3))

z0, z1 = img.range('z')
img + hv.operation.contours(img, levels=5)

For full documentation and the available style and plot options, use

Download this notebook from GitHub (right-click to download).