# Contours ¶

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


A  Contours  object is similar to  Path  object except it may be associated with a numeric value (the  level  ), which can be used to apply colormapping the  Contours  . To see the effect of this we can create a number of  Contours  with varying shapes and  level  values. In this case we will create a number of concentric rings with increasing radii and level values and colormap the  Contours  with the viridis colormap:

In [2]:
%%opts Contours (cmap='viridis')

angles = np.linspace(0, 2*np.pi, 100)

hv.Overlay([hv.Contours([circle(i+0.05)], level=i) for i in np.linspace(0, 1, 10)])

Out[2]:

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 compute an  NdOverlay  containing a  Contours  Element 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 [show_legend=False colorbar=True width=325] (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=np.linspace(z0, z1, 5), overlaid=False)

Out[3]: