holoviews.operation.element module#

Collection of either extremely generic or simple Operation examples.

class holoviews.operation.element.apply_when(*, operation, predicate, name)[source]#

Bases: ParameterizedFunction

Applies a selection depending on the current zoom range. If the supplied predicate function returns a True it will apply the operation otherwise it will return the raw element after the selection. For example the following will apply datashading if the number of points in the current viewport exceed 1000 otherwise just returning the selected points element:

apply_when(points, operation=datashade, predicate=lambda x: x > 1000)

Parameter Definitions


operation = Callable(label='Operation')

predicate = Callable(allow_None=True, label='Predicate')

class holoviews.operation.element.chain(*, operations, output_type, dynamic, group, input_ranges, link_inputs, streams, name)[source]#

Bases: Operation

Defining an Operation chain is an easy way to define a new Operation from a series of existing ones. The argument is a list of Operation (or Operation instances) that are called in sequence to generate the returned element.

chain(operations=[gradient, threshold.instance(level=2)])

This operation can accept an Image instance and would first compute the gradient before thresholding the result at a level of 2.0.

Instances are only required when arguments need to be passed to individual operations so the resulting object is a function over a single argument.

Parameter Definitions


Parameters inherited from:

holoviews.core.operation.Operation: dynamic, input_ranges, link_inputs, streams

group = String(default='', label='Group')

The group assigned to the result after having applied the chain. Defaults to the group produced by the last operation in the chain

output_type = Parameter(default=<class 'holoviews.element.raster.Image'>, label='Output type')

The output type of the chain operation. Must be supplied if the chain is to be used as a channel operation.

operations = List(bounds=(0, None), class_=<class 'holoviews.core.operation.Operation'>, default=[], item_type=<class 'holoviews.core.operation.Operation'>, label='Operations')

A list of Operations (or Operation instances) that are applied on the input from left to right.

find(operation, skip_nonlinked=True)[source]#

Returns the first found occurrence of an operation while performing a backward traversal of the chain pipeline.

output_type[source]#

alias of Image

class holoviews.operation.element.collapse(*, fn, dynamic, group, input_ranges, link_inputs, streams, name)[source]#

Bases: Operation

Given an overlay of Element types, collapse into single Element object using supplied function. Collapsing aggregates over the key dimensions of each object applying the supplied fn to each group.

This is an example of an Operation that does not involve any Raster types.

Parameter Definitions


Parameters inherited from:

holoviews.core.operation.Operation: group, dynamic, input_ranges, link_inputs, streams

fn = Callable(default=<function mean at 0x10881a1f0>, label='Fn')

The function that is used to collapse the curve y-values for each x-value.

fn(axis=None, dtype=None, out=None, keepdims=<no value>, *, where=<no value>)[source]#

Compute the arithmetic mean along the specified axis.

Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. float64 intermediate and return values are used for integer inputs.

Parameters#

aarray_like

Array containing numbers whose mean is desired. If a is not an array, a conversion is attempted.

axisNone or int or tuple of ints, optional

Axis or axes along which the means are computed. The default is to compute the mean of the flattened array.

If this is a tuple of ints, a mean is performed over multiple axes, instead of a single axis or all the axes as before.

dtypedata-type, optional

Type to use in computing the mean. For integer inputs, the default is float64; for floating point inputs, it is the same as the input dtype.

outndarray, optional

Alternate output array in which to place the result. The default is None; if provided, it must have the same shape as the expected output, but the type will be cast if necessary. See ufuncs-output-type for more details. See ufuncs-output-type for more details.

keepdimsbool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

If the default value is passed, then keepdims will not be passed through to the mean method of sub-classes of ndarray, however any non-default value will be. If the sub-class’ method does not implement keepdims any exceptions will be raised.

wherearray_like of bool, optional

Elements to include in the mean. See ~numpy.ufunc.reduce for details.

Added in version 1.20.0.

Returns#

mndarray, see dtype parameter above

If out=None, returns a new array containing the mean values, otherwise a reference to the output array is returned.

See Also#

average : Weighted average std, var, nanmean, nanstd, nanvar

Notes#

The arithmetic mean is the sum of the elements along the axis divided by the number of elements.

Note that for floating-point input, the mean is computed using the same precision the input has. Depending on the input data, this can cause the results to be inaccurate, especially for float32 (see example below). Specifying a higher-precision accumulator using the dtype keyword can alleviate this issue.

By default, float16 results are computed using float32 intermediates for extra precision.

Examples#

>>> import numpy as np
>>> a = np.array([[1, 2], [3, 4]])
>>> np.mean(a)
2.5
>>> np.mean(a, axis=0)
array([2., 3.])
>>> np.mean(a, axis=1)
array([1.5, 3.5])

In single precision, mean can be inaccurate:

>>> a = np.zeros((2, 512*512), dtype=np.float32)
>>> a[0, :] = 1.0
>>> a[1, :] = 0.1
>>> np.mean(a)
np.float32(0.54999924)

Computing the mean in float64 is more accurate:

>>> np.mean(a, dtype=np.float64)
0.55000000074505806 # may vary

Computing the mean in timedelta64 is available:

>>> b = np.array([1, 3], dtype="timedelta64[D]")
>>> np.mean(b)
np.timedelta64(2,'D')

Specifying a where argument:

>>> a = np.array([[5, 9, 13], [14, 10, 12], [11, 15, 19]])
>>> np.mean(a)
12.0
>>> np.mean(a, where=[[True], [False], [False]])
9.0
class holoviews.operation.element.contours(*, filled, levels, overlaid, dynamic, group, input_ranges, link_inputs, streams, name)[source]#

Bases: Operation

Given a Image with a single channel, annotate it with contour lines for a given set of contour levels.

The return is an NdOverlay with a Contours layer for each given level, overlaid on top of the input Image.

Parameter Definitions


Parameters inherited from:

holoviews.core.operation.Operation: dynamic, input_ranges, link_inputs, streams

group = String(default='Level', label='Group')

The group assigned to the output contours.

levels = ClassSelector(class_=(<class 'list'>, <class 'int'>), default=10, label='Levels')

A list of scalar values used to specify the contour levels.

filled = Boolean(default=False, label='Filled')

Whether to generate filled contours

overlaid = Boolean(default=False, label='Overlaid')

Whether to overlay the contour on the supplied Element.

output_type[source]#

alias of Overlay

class holoviews.operation.element.convolve(*, kernel_roi, dynamic, group, input_ranges, link_inputs, streams, name)[source]#

Bases: Operation

Apply a convolution to an overlay using the top layer as the kernel for convolving the bottom layer. Both Image elements in the input overlay should have a single value dimension.

Parameter Definitions


Parameters inherited from:

holoviews.core.operation.Operation: dynamic, input_ranges, link_inputs, streams

group = String(default='Convolution', label='Group')

The group assigned to the convolved output.

kernel_roi = NumericTuple(default=(0, 0, 0, 0), label='Kernel roi', length=4)

A 2-dimensional slice of the kernel layer to use in the convolution in lbrt (left, bottom, right, top) format. By default, no slicing is applied.

output_type[source]#

alias of Image

class holoviews.operation.element.decimate(*, max_samples, random_seed, x_range, y_range, dynamic, group, input_ranges, link_inputs, streams, name)[source]#

Bases: Operation

Decimates any column based Element to a specified number of random rows if the current element defined by the x_range and y_range contains more than max_samples. By default the operation returns a DynamicMap with a RangeXY stream allowing dynamic downsampling.

Parameter Definitions


Parameters inherited from:

dynamic = Boolean(default=True, label='Dynamic')

Enables dynamic processing by default.

link_inputs = Boolean(default=True, label='Link inputs')

By default, the link_inputs parameter is set to True so that when applying shade, backends that support linked streams update RangeXY streams on the inputs of the shade operation.

streams = ClassSelector(class_=(<class 'dict'>, <class 'list'>), default=[<class 'holoviews.streams.RangeXY'>], label='Streams')

List of streams that are applied if dynamic=True, allowing for dynamic interaction with the plot.

max_samples = Integer(default=5000, inclusive_bounds=(True, True), label='Max samples')

Maximum number of samples to display at the same time.

random_seed = Integer(default=42, inclusive_bounds=(True, True), label='Random seed')

Seed used to initialize randomization.

x_range = NumericTuple(allow_None=True, label='X range', length=2)

The x_range as a tuple of min and max x-value. Auto-ranges if set to None.

y_range = NumericTuple(allow_None=True, label='Y range', length=2)

The x_range as a tuple of min and max y-value. Auto-ranges if set to None.

class holoviews.operation.element.dendrogram(*, adjoined, adjoint_dims, main_dim, main_element, optimal_ordering, dynamic, group, input_ranges, link_inputs, streams, name)[source]#

Bases: Operation

The dendrogram operation computes one or two adjoint dendrogram of the data along the specified dimension(s). The operation uses the scipy dendrogram algorithm to compute the tree structure of the data. The operation is typically used to visualize hierarchical clustering of the data.

Parameter Definitions


Parameters inherited from:

holoviews.core.operation.Operation: group, dynamic, input_ranges, link_inputs, streams

adjoined = Boolean(default=True, label='Adjoined')

Whether to adjoin the dendrogram(s) to the main plot

adjoint_dims = List(bounds=(0, None), class_=<class 'str'>, default=[], item_type=<class 'str'>, label='Adjoint dims')

The adjoint dimension to cluster on

main_dim = String(default='', label='Main dim')

The main dimension to cluster on

main_element = ClassSelector(class_=<class 'holoviews.core.data.Dataset'>, default=<class 'holoviews.element.raster.HeatMap'>, label='Main element')

The Element type to use for the main plot if the input is a Dataset.

optimal_ordering = Boolean(default=False, label='Optimal ordering')

If True, the linkage matrix will be reordered so that the distance between successive leaves is minimal. This results in a more intuitive tree structure when the data are visualized. defaults to False, because this algorithm can be slow, particularly on large datasets. See for more information: https://docs.scipy.org/doc/scipy/reference/generated/scipy.cluster.hierarchy.linkage.html#scipy.cluster.hierarchy.linkage

main_element[source]#

alias of HeatMap

class holoviews.operation.element.factory(*, args, kwargs, output_type, dynamic, group, input_ranges, link_inputs, streams, name)[source]#

Bases: Operation

Simple operation that constructs any element that accepts some other element as input. For instance, RGB and HSV elements can be created from overlays of Image elements.

Parameter Definitions


Parameters inherited from:

holoviews.core.operation.Operation: group, dynamic, input_ranges, link_inputs, streams

output_type = Parameter(default=<class 'holoviews.element.raster.RGB'>, label='Output type')

The output type of the factor operation. By default, if three overlaid Images elements are supplied, the corresponding RGB element will be returned.

args = List(bounds=(0, None), default=[], label='Args')

The list of positional argument to pass to the factory

kwargs = Dict(class_=<class 'dict'>, default={}, label='Kwargs')

The dict of keyword arguments to pass to the factory

output_type[source]#

alias of RGB

class holoviews.operation.element.function(*, args, fn, input_type, kwargs, output_type, dynamic, group, input_ranges, link_inputs, streams, name)[source]#

Bases: Operation

Parameter Definitions


Parameters inherited from:

holoviews.core.operation.Operation: group, dynamic, input_ranges, link_inputs, streams

output_type = ClassSelector(allow_None=True, class_=<class 'type'>, label='Output type')

The output type of the method operation

input_type = ClassSelector(allow_None=True, class_=<class 'type'>, label='Input type')

The object type the method is defined on

fn = Callable(label='Fn')

The function to apply.

args = List(bounds=(0, None), default=[], label='Args')

The list of positional argument to pass to the method

kwargs = Dict(class_=<class 'dict'>, default={}, label='Kwargs')

The dict of keyword arguments to pass to the method

class holoviews.operation.element.gradient(*, dynamic, group, input_ranges, link_inputs, streams, name)[source]#

Bases: Operation

Compute the gradient plot of the supplied Image.

If the Image value dimension is cyclic, the smallest step is taken considered the cyclic range

Parameter Definitions


Parameters inherited from:

holoviews.core.operation.Operation: dynamic, input_ranges, link_inputs, streams

group = String(default='Gradient', label='Group')

The group assigned to the output gradient matrix.

output_type[source]#

alias of Image

class holoviews.operation.element.gridmatrix(*, chart_type, diagonal_operation, diagonal_type, overlay_dims, name)[source]#

Bases: ParameterizedFunction

The gridmatrix operation takes an Element or HoloMap of Elements as input and creates a GridMatrix object, which plots each dimension in the Element against each other dimension. This provides a very useful overview of high-dimensional data and is inspired by pandas and seaborn scatter_matrix implementations.

Parameter Definitions


chart_type = Parameter(default=<class 'holoviews.element.chart.Scatter'>, label='Chart type')

The Element type used to display bivariate distributions of the data.

diagonal_type = Parameter(allow_None=True, label='Diagonal type')

The Element type along the diagonal, may be a Histogram or any other plot type which can visualize a univariate distribution. This parameter overrides diagonal_operation.

diagonal_operation = Parameter(default=<class 'holoviews.operation.element.histogram'>, label='Diagonal operation')

The operation applied along the diagonal, may be a histogram-operation or any other function which returns a viewable element.

overlay_dims = List(bounds=(0, None), default=[], label='Overlay dims')

If a HoloMap is supplied, this will allow overlaying one or more of its key dimensions.

chart_type[source]#

alias of Scatter

diagonal_operation[source]#

alias of histogram

class holoviews.operation.element.histogram(*, bin_range, bins, cumulative, dimension, frequency_label, groupby, groupby_range, log, mean_weighted, nonzero, normed, num_bins, style_prefix, weight_dimension, dynamic, group, input_ranges, link_inputs, streams, name)[source]#

Bases: Operation

Returns a Histogram of the input element data, binned into num_bins over the bin_range (if specified) along the specified dimension.

Parameter Definitions


Parameters inherited from:

holoviews.core.operation.Operation: group, dynamic, input_ranges, link_inputs, streams

bin_range = NumericTuple(allow_None=True, label='Bin range', length=2)

Specifies the range within which to compute the bins.

bins = ClassSelector(allow_None=True, class_=(<class 'numpy.ndarray'>, <class 'list'>, <class 'tuple'>, <class 'str'>), label='Bins')

An explicit set of bin edges or a method to find the optimal set of bin edges, e.g. ‘auto’, ‘fd’, ‘scott’ etc. For more documentation on these approaches see the np.histogram_bin_edges documentation.

cumulative = Boolean(default=False, label='Cumulative')

Whether to compute the cumulative histogram

dimension = String(allow_None=True, label='Dimension')

Along which dimension of the Element to compute the histogram.

frequency_label = String(allow_None=True, label='Frequency label')

Format string defining the label of the frequency dimension of the Histogram.

groupby = ClassSelector(allow_None=True, class_=(<class 'str'>, <class 'holoviews.core.dimension.Dimension'>), label='Groupby')

Defines a dimension to group the Histogram returning an NdOverlay of Histograms.

groupby_range = Selector(default='shared', label='Groupby range', names={}, objects=['shared', 'separated'])

Whether to group the histograms along the same range or separate them.

log = Boolean(default=False, label='Log')

Whether to use base 10 logarithmic samples for the bin edges.

mean_weighted = Boolean(default=False, label='Mean weighted')

Whether the weighted frequencies are averaged.

normed = Selector(default=False, label='Normed', names={}, objects=[True, False, 'integral', 'height'])

Controls normalization behavior. If True or ‘integral’, then density=True is passed to np.histogram, and the distribution is normalized such that the integral is unity. If False, then the frequencies will be raw counts. If ‘height’, then the frequencies are normalized such that the max bin height is unity.

nonzero = Boolean(default=False, label='Nonzero')

Whether to use only nonzero values when computing the histogram

num_bins = Integer(default=20, inclusive_bounds=(True, True), label='Num bins')

Number of bins in the histogram .

weight_dimension = String(allow_None=True, label='Weight dimension')

Name of the dimension the weighting should be drawn from

style_prefix = String(allow_None=True, label='Style prefix')

Used for setting a common style for histograms in a HoloMap or AdjointLayout.

class holoviews.operation.element.image_overlay(*, default_range, fill, spec, dynamic, group, input_ranges, link_inputs, streams, name)[source]#

Bases: Operation

Operation to build a overlay of images to a specification from a subset of the required elements.

This is useful for reordering the elements of an overlay, duplicating layers of an overlay or creating blank image elements in the appropriate positions.

For instance, image_overlay may build a three layered input suitable for the RGB factory operation even if supplied with one or two of the required channels (creating blank channels for the missing elements).

Note that if there is any ambiguity regarding the match, the strongest match will be used. In the case of a tie in match strength, the first layer in the input is used. One successful match is always required.

Parameter Definitions


Parameters inherited from:

holoviews.core.operation.Operation: dynamic, input_ranges, link_inputs, streams

group = String(default='Transform', label='Group')

The group assigned to the resulting overlay.

spec = String(default='', label='Spec')

Specification of the output Overlay structure. For instance: Image.R * Image.G * Image.B Will ensure an overlay of this structure is created even if (for instance) only (Image.R * Image.B) is supplied. Elements in the input overlay that match are placed in the appropriate positions and unavailable specification elements are created with the specified fill group.

fill = Number(default=0, inclusive_bounds=(True, True), label='Fill')

default_range = Tuple(default=(0, 1), label='Default range', length=2)

The default range that will be set on the value_dimension of any automatically created blank image elements.

output_type[source]#

alias of Overlay

class holoviews.operation.element.interpolate_curve(*, interpolation, dynamic, group, input_ranges, link_inputs, streams, name)[source]#

Bases: Operation

Resamples a Curve using the defined interpolation method, e.g. to represent changes in y-values as steps.

Parameter Definitions


Parameters inherited from:

holoviews.core.operation.Operation: group, dynamic, input_ranges, link_inputs, streams

interpolation = Selector(default='steps-mid', label='Interpolation', names={}, objects=['steps-pre', 'steps-mid', 'steps-post', 'linear'])

Controls the transition point of the step along the x-axis.

class holoviews.operation.element.method(*, args, input_type, kwargs, method_name, output_type, dynamic, group, input_ranges, link_inputs, streams, name)[source]#

Bases: Operation

Operation that wraps a method call

Parameter Definitions


Parameters inherited from:

holoviews.core.operation.Operation: group, dynamic, input_ranges, link_inputs, streams

output_type = ClassSelector(allow_None=True, class_=<class 'type'>, label='Output type')

The output type of the method operation

input_type = ClassSelector(allow_None=True, class_=<class 'type'>, label='Input type')

The object type the method is defined on

method_name = String(default='__call__', label='Method name')

The method name

args = List(bounds=(0, None), default=[], label='Args')

The list of positional argument to pass to the method

kwargs = Dict(class_=<class 'dict'>, default={}, label='Kwargs')

The dict of keyword arguments to pass to the method

class holoviews.operation.element.operation(*, op, output_type, dynamic, group, input_ranges, link_inputs, streams, name)[source]#

Bases: Operation

The most generic operation that wraps any callable into an Operation. The callable needs to accept an HoloViews component and a key (that may be ignored) and must return a new HoloViews component.

This class may be useful for turning a HoloViews method into an operation to define as compositor operation. For instance, the following definition:

operation.instance(op=lambda x, k: x.collapse(np.subtract))

Could be used to implement a collapse operation to subtracts the data between Rasters in an Overlay.

Parameter Definitions


Parameters inherited from:

holoviews.core.operation.Operation: dynamic, input_ranges, link_inputs, streams

group = String(default='Operation', label='Group')

The group assigned to the result after having applied the operator.

output_type = Parameter(allow_None=True, label='Output type')

The output element type which may be None to disable type checking. May be used to declare useful information to other code in HoloViews, e.g. required for tab-completion support of operations registered with compositors.

op = Callable(label='Op')

The operation used to generate a new HoloViews object returned by the operation. By default, the identity operation is applied.

class holoviews.operation.element.threshold(*, high, level, low, dynamic, group, input_ranges, link_inputs, streams, name)[source]#

Bases: Operation

Threshold a given Image whereby all values higher than a given level map to the specified high value and all values lower than that level map to the specified low value.

Parameter Definitions


Parameters inherited from:

holoviews.core.operation.Operation: dynamic, input_ranges, link_inputs, streams

group = String(default='Threshold', label='Group')

The group assigned to the thresholded output.

level = Number(default=0.5, inclusive_bounds=(True, True), label='Level')

The value at which the threshold is applied. Values lower than the threshold map to the ‘low’ value and values above map to the ‘high’ value.

high = Number(default=1.0, inclusive_bounds=(True, True), label='High')

The value given to elements greater than (or equal to) the threshold.

low = Number(default=0.0, inclusive_bounds=(True, True), label='Low')

The value given to elements below the threshold.

output_type[source]#

alias of Image

class holoviews.operation.element.transform(*, operator, dynamic, group, input_ranges, link_inputs, streams, name)[source]#

Bases: Operation

Generic Operation to transform an input Image or RGBA element into an output Image. The transformation is defined by the supplied callable that accepts the data of the input Image (typically a numpy array) and returns the transformed data of the output Image.

This operator is extremely versatile; for instance, you could implement an alternative to the explicit threshold operator with:

operator=lambda x: np.clip(x, 0, 0.5)

Alternatively, you can implement a transform computing the 2D autocorrelation using the scipy library with:

operator=lambda x: scipy.signal.correlate2d(x, x)

Parameter Definitions


Parameters inherited from:

holoviews.core.operation.Operation: dynamic, input_ranges, link_inputs, streams

group = String(default='Transform', label='Group')

The group assigned to the result after applying the transform.

operator = Callable(allow_None=True, label='Operator')

Function of one argument that transforms the data in the input Image to the data in the output Image. By default, acts as the identity function such that the output matches the input.

output_type[source]#

alias of Image