holoviews.element.raster module#

class holoviews.element.raster.HSV(data=None, kdims=None, vdims=None, **kwargs)[source]#

Bases: RGB

HSV represents a regularly spaced 2D grid of an underlying continuous space of HSV (hue, saturation and value) color space values. The definition of the grid closely matches the semantics of an Image or RGB element and in the simplest case the grid may be specified as a NxMx3 or NxMx4 array of values along with a bounds, but it may also be defined through explicit and regularly spaced x/y-coordinate arrays. The two most basic supported constructors of an HSV element therefore include:

HSV((X, Y, H, S, V))

where X is a 1D array of shape M, Y is a 1D array of shape N and H/S/V are 2D array of shape NxM, or equivalently:

HSV(Z, bounds=(x0, y0, x1, y1))

where Z is a 3D array of stacked H/S/V arrays with shape NxMx3/4 and the bounds define the (left, bottom, top, right) edges of the four corners of the grid. Other gridded formats which support declaring of explicit x/y-coordinate arrays such as xarray are also supported.

Note that the interpretation of the orientation changes depending on whether bounds or explicit coordinates are used.

Parameter Definitions


Parameters inherited from:

group = String(constant=True, default='HSV', label='Group')

A string describing the data wrapped by the object.

vdims = List(bounds=(3, 4), default=[Dimension('H'), Dimension('S'), Dimension('V')], label='Vdims')

The dimension description of the data held in the array. If an alpha channel is supplied, the defined alpha_dimension is automatically appended to this list.

alpha_dimension = ClassSelector(class_=<class 'holoviews.core.dimension.Dimension'>, default=Dimension('A'), label='Alpha dimension')

The alpha dimension definition to add the value dimensions if an alpha channel is supplied.

property rgb#

Conversion from HSV to RGB.

class holoviews.element.raster.HeatMap(data=None, kdims=None, vdims=None, **kwargs)[source]#

Bases: Selection2DExpr, Dataset, Element2D

HeatMap represents a 2D grid of categorical coordinates which can be computed from a sparse tabular representation. A HeatMap does not automatically aggregate the supplied values, so if the data contains multiple entries for the same coordinate on the 2D grid it should be aggregated using the aggregate method before display.

The HeatMap constructor will support any tabular or gridded data format with 2 coordinates and at least one value dimension. A simple example:

HeatMap([(x1, y1, z1), (x2, y2, z2), …])

However any tabular and gridded format, including pandas DataFrames, dictionaries of columns, xarray DataArrays and more are supported if the library is importable.

Parameter Definitions


Parameters inherited from:

group = String(constant=True, default='HeatMap', label='Group')

A string describing the data wrapped by the object.

kdims = List(bounds=(2, 2), constant=True, default=[Dimension('x'), Dimension('y')], label='Kdims')

The key dimensions defined as list of dimensions that may be used in indexing (and potential slicing) semantics. The order of the dimensions listed here determines the semantics of each component of a multi-dimensional indexing operation. Aliased with key_dimensions.

vdims = List(bounds=(0, None), constant=True, default=[Dimension('z')], label='Vdims')

The value dimensions defined as the list of dimensions used to describe the components of the data. If multiple value dimensions are supplied, a particular value dimension may be indexed by name after the key dimensions. Aliased with value_dimensions.

range(dim, data_range=True, dimension_range=True)[source]#

Return the lower and upper bounds of values along dimension.

Parameters#

dimension

The dimension to compute the range on.

data_rangebool

Compute range from data values

dimension_rangebool

Include Dimension ranges Whether to include Dimension range and soft_range in range calculation

Returns#

Tuple containing the lower and upper bound

class holoviews.element.raster.Image(data=None, kdims=None, vdims=None, **kwargs)[source]#

Bases: Selection2DExpr, Dataset, Raster, SheetCoordinateSystem

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, top, right) 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.

Note that the interpretation of the orientation of the array changes depending on whether bounds or explicit coordinates are used.

Parameter Definitions


Parameters inherited from:

group = String(constant=True, default='Image', label='Group')

A string describing the data wrapped by the object.

kdims = List(bounds=(2, 2), constant=True, default=[Dimension('x'), Dimension('y')], label='Kdims')

The label of the x- and y-dimension of the Raster in the form of a string or dimension object.

vdims = List(bounds=(1, None), default=[Dimension('z')], label='Vdims')

The dimension description of the data held in the matrix.

datatype = List(bounds=(0, None), default=['grid', 'xarray', 'image', 'cube', 'dataframe', 'dictionary'], label='Datatype')

A priority list of the data types to be used for storage on the .data attribute. If the input supplied to the element constructor cannot be put into the requested format, the next format listed will be used until a suitable format is found (or the data fails to be understood).

bounds = ClassSelector(class_=<class 'holoviews.core.boundingregion.BoundingRegion'>, default=BoundingBox(radius=0.5), label='Bounds')

The bounding region in sheet coordinates containing the data.

rtol = Number(allow_None=True, inclusive_bounds=(True, True), label='Rtol')

The tolerance used to enforce regular sampling for regular, gridded data where regular sampling is expected. Expressed as the maximal allowable sampling difference between sample locations.

aggregate(dimensions=None, function=None, spreadfn=None, **kwargs)[source]#

Aggregates data on the supplied dimensions.

Aggregates over the supplied key dimensions with the defined function or dim_transform specified as a tuple of the transformed dimension name and dim transform.

Parameters#

dimensions

Dimension(s) to aggregate on Default to all key dimensions

function

Aggregation function or transform to apply Supports both simple functions and dimension transforms

spreadfn

Secondary reduction to compute value spread Useful for computing a confidence interval, spread, or standard deviation.

**kwargs

Keyword arguments either passed to the aggregation function or to create new names for the transformed variables

Returns#

Returns the aggregated Dataset

clone(data=None, shared_data=True, new_type=None, link=True, *args, **overrides)[source]#

Returns a clone of the object with matching parameter values containing the specified args and kwargs.

If shared_data is set to True and no data explicitly supplied, the clone will share data with the original. May also supply a new_type, which will inherit all shared parameters.

closest(coords=None, **kwargs)[source]#

Given a single coordinate or multiple coordinates as a tuple or list of tuples or keyword arguments matching the dimension closest will find the closest actual x/y coordinates.

range(dim, data_range=True, dimension_range=True)[source]#

Return the lower and upper bounds of values along dimension.

Parameters#

dim

The dimension to compute the range on.

data_rangebool

Compute range from data values

dimension_rangebool

Include Dimension ranges Whether to include Dimension range and soft_range in range calculation

Returns#

Tuple containing the lower and upper bound

select(selection_specs=None, **selection)[source]#

Allows selecting data by the slices, sets and scalar values along a particular dimension. The indices should be supplied as keywords mapping between the selected dimension and value. Additionally selection_specs (taking the form of a list of type.group.label strings, types or functions) may be supplied, which will ensure the selection is only applied if the specs match the selected object.

class holoviews.element.raster.ImageStack(data=None, kdims=None, vdims=None, **kwargs)[source]#

Bases: Image

ImageStack expands the capabilities of Image to by supporting multiple layers of images.

As there is many ways to represent multiple layers of images, the following options are supported:

  1. A 3D Numpy array with the shape (y, x, level)

  2. A list of 2D Numpy arrays with identical shape (y, x)

  3. A dictionary where the keys will be set as the vdims and the

    values are 2D Numpy arrays with identical shapes (y, x). If the dictionary’s keys matches the kdims of the element, they need to be 1D arrays.

  4. A tuple containing (x, y, level_0, level_1, …),

    where the level is a 2D Numpy array in the shape of (y, x).

  5. An xarray DataArray or Dataset where its coords contain the kdims.

If no kdims are supplied, x and y are used.

If no vdims are supplied, and the naming can be inferred like with a dictionary the levels will be named level_0, level_1, etc.

Parameter Definitions


Parameters inherited from:

group = String(constant=True, default='ImageStack', label='Group')

A string describing the data wrapped by the object.

vdims = List(bounds=(1, None), default=[Dimension('z')], label='Vdims')

The dimension description of the data held in the matrix.

class holoviews.element.raster.QuadMesh(data=None, kdims=None, vdims=None, **kwargs)[source]#

Bases: Selection2DExpr, Dataset, Element2D

A QuadMesh represents 2D rectangular grid expressed as x- and y-coordinates defined as 1D or 2D arrays. Unlike the Image type a QuadMesh may be regularly or irregularly spaced and contain either bin edges or bin centers. If bin edges are supplied the shape of the x/y-coordinate arrays should be one greater than the shape of the value array.

The default interface expects data to be specified in the form:

QuadMesh((X, Y, Z))

where X and Y may be 1D or 2D arrays of the shape N(+1) and M(+1) respectively or N(+1)xM(+1) and the Z value array should be of shape NxM. Other gridded formats such as xarray are also supported if installed.

The grid orientation follows the standard matrix convention: An array Z with shape (nrows, ncolumns) is plotted with the column number as X and the row number as Y.

Parameter Definitions


Parameters inherited from:

group = String(constant=True, default='QuadMesh', label='Group')

A string describing the data wrapped by the object.

kdims = List(bounds=(2, 2), constant=True, default=[Dimension('x'), Dimension('y')], label='Kdims')

The key dimensions defined as list of dimensions that may be used in indexing (and potential slicing) semantics. The order of the dimensions listed here determines the semantics of each component of a multi-dimensional indexing operation. Aliased with key_dimensions.

vdims = List(bounds=(1, None), default=[Dimension('z')], label='Vdims')

The value dimensions defined as the list of dimensions used to describe the components of the data. If multiple value dimensions are supplied, a particular value dimension may be indexed by name after the key dimensions. Aliased with value_dimensions.

trimesh()[source]#

Converts a QuadMesh into a TriMesh.

class holoviews.element.raster.RGB(data=None, kdims=None, vdims=None, **kwargs)[source]#

Bases: Image

RGB represents a regularly spaced 2D grid of an underlying continuous space of RGB(A) (red, green, blue and alpha) color space values. The definition of the grid closely matches the semantics of an Image and in the simplest case the grid may be specified as a NxMx3 or NxMx4 array of values along with a bounds, but it may also be defined through explicit and regularly spaced x/y-coordinate arrays. The two most basic supported constructors of an RGB element therefore include:

RGB((X, Y, R, G, B))

where X is a 1D array of shape M, Y is a 1D array of shape N and R/G/B are 2D array of shape NxM, or equivalently:

RGB(Z, bounds=(x0, y0, x1, y1))

where Z is a 3D array of stacked R/G/B arrays with shape NxMx3/4 and the bounds define the (left, bottom, top, right) edges of the four corners of the grid. Other gridded formats which support declaring of explicit x/y-coordinate arrays such as xarray are also supported.

Note that the interpretation of the orientation changes depending on whether bounds or explicit coordinates are used.

Parameter Definitions


Parameters inherited from:

group = String(constant=True, default='RGB', label='Group')

A string describing the data wrapped by the object.

vdims = List(bounds=(3, 4), default=[Dimension('R'), Dimension('G'), Dimension('B')], label='Vdims')

The dimension description of the data held in the matrix. If an alpha channel is supplied, the defined alpha_dimension is automatically appended to this list.

alpha_dimension = ClassSelector(class_=<class 'holoviews.core.dimension.Dimension'>, default=Dimension('A'), label='Alpha dimension')

The alpha dimension definition to add the value dimensions if an alpha channel is supplied.

classmethod load_image(filename, height=1, array=False, bounds=None, bare=False, **kwargs)[source]#

Load an image from a file and return an RGB element or array

Parameters#

filename

Filename of the image to be loaded

height

Determines the bounds of the image where the width is scaled relative to the aspect ratio of the image.

array

Whether to return an array (rather than RGB default)

bounds

Bounds for the returned RGB (overrides height)

bare

Whether to hide the axes

kwargs

Additional kwargs to the RGB constructor

Returns#

RGB element or array

property rgb#

Returns the corresponding RGB element.

Other than the updating parameter definitions, this is the only change needed to implemented an arbitrary colorspace as a subclass of RGB.

class holoviews.element.raster.Raster(data, kdims=None, vdims=None, extents=None, **params)[source]#

Bases: Element2D

Raster is a basic 2D element type for presenting either numpy or dask arrays as two dimensional raster images.

Arrays with a shape of (N,M) are valid inputs for Raster whereas subclasses of Raster (e.g. RGB) may also accept 3D arrays containing channel information.

Raster does not support slicing like the Image or RGB subclasses and the extents are in matrix coordinates if not explicitly specified.

Parameter Definitions


Parameters inherited from:

group = String(constant=True, default='Raster', label='Group')

A string describing the data wrapped by the object.

kdims = List(bounds=(2, 2), constant=True, default=[Dimension('x'), Dimension('y')], label='Kdims')

The label of the x- and y-dimension of the Raster in form of a string or dimension object.

vdims = List(bounds=(1, None), default=[Dimension('z')], label='Vdims')

The dimension description of the data held in the matrix.

dimension_values(dim, expanded=True, flat=True)[source]#

The set of samples available along a particular dimension.

range(dim, data_range=True, dimension_range=True)[source]#

Return the lower and upper bounds of values along dimension.

Parameters#

dimension

The dimension to compute the range on.

data_rangebool

Compute range from data values

dimension_rangebool

Include Dimension ranges Whether to include Dimension range and soft_range in range calculation

Returns#

Tuple containing the lower and upper bound

reduce(dimensions=None, function=None, **reduce_map)[source]#

Reduces the Raster using functions provided via the kwargs, where the keyword is the dimension to be reduced. Optionally a label_prefix can be provided to prepend to the result Element label.

sample(samples=None, bounds=None, **sample_values)[source]#

Sample the Raster along one or both of its dimensions, returning a reduced dimensionality type, which is either a ItemTable, Curve or Scatter. If two dimension samples and a new_xaxis is provided the sample will be the value of the sampled unit indexed by the value in the new_xaxis tuple.