Image#
Download this notebook from GitHub (right-click to download).
- Title
- Image Element
- Dependencies
- Bokeh
- Backends
- Bokeh
- Matplotlib
- Plotly
import numpy as np
import holoviews as hv
from holoviews import opts
hv.extension('bokeh')
Image represents a regularly sampled 2D grid of an underlying continuous space of intensity values, which will be colormapped on plotting. The grid of intensity values may be specified as a NxM
sized array of values along with a bounds, but it may also be defined through explicit and regularly spaced x/y-coordinate arrays of shape M
and N
respectively. The two most basic supported constructors of an Image therefore include:
Image((X, Y, Z))
where X
is a 1D array of shape M
, Y
is a 1D array of shape N
and Z
is a 2D array of shape NxM
, or equivalently:
Image(Z, bounds=(x0, y0, x1, y1))
where Z
is a 2D array of shape NxM
defining the intensity values and the bounds define the (left, bottom, right, top) edges of four corners of the grid. Other gridded formats which support declaring of explicit x/y-coordinate arrays such as xarray are also supported. See the Gridded Datasets user guide for all the other accepted data formats.
ls = np.linspace(0, 10, 200)
xx, yy = np.meshgrid(ls, ls)
bounds=(-1,-1,1,1) # Coordinate system: (left, bottom, right, top)
img = hv.Image(np.sin(xx)*np.cos(yy), bounds=bounds)
img
In recent versions of Bokeh, you can enable image hover to inspect the raw values:
opts.defaults(
opts.Image(tools=['hover']),
opts.Points (color='black', marker='x', size=20))
Slicing, sampling, etc. on an Image
all operate in this continuous space, whereas the corresponding operations on a Raster
work on the raw array coordinates.
img + img[-0.5:0.5, -0.5:0.5]