Box

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


Title
Box Element
Dependencies
Matplotlib
Backends
Matplotlib
Bokeh
In [1]:
import numpy as np
import holoviews as hv
from holoviews import opts

hv.extension('matplotlib')

A Box is an annotation that takes a center x-position, a center y-position and a size:

In [2]:
data = np.sin(np.mgrid[0:100,0:100][1]/10.0)
data[np.arange(40, 60), np.arange(20, 40)] = -1
data[np.arange(40, 50), np.arange(70, 80)] = -3    
(hv.Image(data) * hv.Box(-0.2, 0, 0.25 ) * hv.Box(-0, 0, (0.4,0.9))).opts(
    opts.Box(color='red', linewidth=5),
    opts.Image(cmap='gray'))
Out[2]:

In addition to these arguments, it supports an optional aspect ratio:

By default, the size argument results in a square such as the small square shown above. Alternatively, the size can be given as the tuple (width, height) resulting in a rectangle. If you only supply a size value, you can still specify a rectangle by specifying an optional aspect value. In addition, you can also set the orientation (in radians, rotating anticlockwise):

In [3]:
data = np.sin(np.mgrid[0:100,0:100][1]/10.0)
data[np.arange(30, 70), np.arange(30, 70)] = -3
box = hv.Box(-0, 0, 0.25, aspect=3, orientation=-np.pi/4)

(hv.Image(data) * box).opts(
    opts.Box(color='purple', linewidth=5),
    opts.Image(cmap='gray'))
Out[3]:

For full documentation and the available style and plot options, use hv.help(hv.Box).


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