Polygons

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

A Polygons object is similar to a Contours object except that each supplied path is closed and filled. Just like Contours , an optional level value may be supplied; the Polygons will then be colored according to the supplied cmap . Non-finite values such as np.NaN or np.inf will default to the supplied facecolor .

Polygons with values can be used to build heatmaps with arbitrary shapes.

In [2]:
%%opts Polygons (cmap='hot' edgecolor='black' linewidth=2)
np.random.seed(35)
hv.Polygons([np.random.rand(4,2)], level=0.5) *\
hv.Polygons([np.random.rand(4,2)], level=1.0) *\
hv.Polygons([np.random.rand(4,2)], level=1.5) *\
hv.Polygons([np.random.rand(4,2)], level=2.0)
Out[2]:

Polygons without a value are useful as annotation, but also allow us to draw arbitrary shapes.

In [3]:
def rectangle(x=0, y=0, width=1, height=1):
    return np.array([(x,y), (x+width, y), (x+width, y+height), (x, y+height)])

(hv.Polygons([rectangle(width=2), rectangle(x=6, width=2)])(style={'facecolor': '#a50d0d'})
* hv.Polygons([rectangle(x=2, height=2), rectangle(x=5, height=2)])(style={'facecolor': '#ffcc00'})
* hv.Polygons([rectangle(x=3, height=2, width=2)])(style={'facecolor': 'cyan'}))
Out[3]:

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