holoviews.core.spaces module#

class holoviews.core.spaces.Callable(callable, **params)[source]#

Bases: Parameterized

Callable allows wrapping callbacks on one or more DynamicMaps allowing their inputs (and in future outputs) to be defined. This makes it possible to wrap DynamicMaps with streams and makes it possible to traverse the graph of operations applied to a DynamicMap.

Additionally, if the memoize attribute is True, a Callable will memoize the last returned value based on the arguments to the function and the state of all streams on its inputs, to avoid calling the function unnecessarily. Note that because memoization includes the streams found on the inputs it may be disabled if the stream requires it and is triggering.

A Callable may also specify a stream_mapping which specifies the objects that are associated with interactive (i.e. linked) streams when composite objects such as Layouts are returned from the callback. This is required for building interactive, linked visualizations (for the backends that support them) when returning Layouts, NdLayouts or GridSpace objects. When chaining multiple DynamicMaps into a pipeline, the link_inputs parameter declares whether the visualization generated using this Callable will inherit the linked streams. This parameter is used as a hint by the applicable backend.

The mapping should map from an appropriate key to a list of streams associated with the selected object. The appropriate key may be a type[.group][.label] specification for Layouts, an integer index or a suitable NdLayout/GridSpace key. For more information see the DynamicMap tutorial at holoviews.org.

Parameter Definitions


callable = Callable(allow_None=True, constant=True, label='Callable')

The callable function being wrapped.

inputs = List(bounds=(0, None), constant=True, default=[], label='Inputs')

The list of inputs the callable function is wrapping. Used to allow deep access to streams in chained Callables.

operation_kwargs = Dict(class_=<class 'dict'>, constant=True, default={}, label='Operation kwargs')

Potential dynamic keyword arguments associated with the operation.

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

If the Callable wraps around other DynamicMaps in its inputs, determines whether linked streams attached to the inputs are transferred to the objects returned by the Callable. For example the Callable wraps a DynamicMap with an RangeXY stream, this switch determines whether the corresponding visualization should update this stream with range changes originating from the newly generated axes.

memoize = Boolean(default=True, label='Memoize')

Whether the return value of the callable should be memoized based on the call arguments and any streams attached to the inputs.

operation = Callable(allow_None=True, label='Operation')

The function being applied by the Callable. May be used to record the transform(s) being applied inside the callback function.

stream_mapping = Dict(class_=<class 'dict'>, constant=True, default={}, label='Stream mapping')

Defines how streams should be mapped to objects returned by the Callable, e.g. when it returns a Layout.

clone(callable=None, **overrides)[source]#

Clones the Callable optionally with new settings

Parameters#

callable

New callable function to wrap

**overrides

Parameter overrides to apply

Returns#

Cloned Callable object

property noargs#

Returns True if the callable takes no arguments

class holoviews.core.spaces.DynamicMap(callback, initial_items=None, streams=None, **params)[source]#

Bases: HoloMap

A DynamicMap is a type of HoloMap where the elements are dynamically generated by a callable. The callable is invoked with values associated with the key dimensions or with values supplied by stream parameters.

Parameter Definitions


Parameters inherited from:

kdims = List(bounds=(0, None), constant=True, default=[], label='Kdims')

The key dimensions of a DynamicMap map to the arguments of the callback. This mapping can be by position or by name.

callback = ClassSelector(allow_None=True, class_=<class 'holoviews.core.spaces.Callable'>, constant=True, label='Callback')

The callable used to generate the elements. The arguments to the callable includes any number of declared key dimensions as well as any number of stream parameters defined on the input streams. If the callable is an instance of Callable it will be used directly, otherwise it will be automatically wrapped in one.

streams = List(bounds=(0, None), constant=True, default=[], label='Streams')

List of Stream instances to associate with the DynamicMap. The set of parameter values across these streams will be supplied as keyword arguments to the callback when the events are received, updating the streams. Can also be supplied as a dictionary that maps parameters or panel widgets to callback argument names that will then be automatically converted to the equivalent list format.

cache_size = Integer(bounds=(1, None), default=500, inclusive_bounds=(True, True), label='Cache size')

The number of entries to cache for fast access. This is an LRU cache where the least recently used item is overwritten once the cache is full.

positional_stream_args = Boolean(constant=True, default=False, label='Positional stream args')

If False, stream parameters are passed to the callback as keyword arguments. If True, stream parameters are passed to callback as positional arguments. Each positional argument is a dict containing the contents of a stream. The positional stream arguments follow the positional arguments for each kdim, and they are ordered to match the order of the DynamicMap’s streams list.

add_dimension(dimension, dim_pos, dim_val, vdim=False, **kwargs)[source]#

Adds a dimension and its values to the object

Requires the dimension name or object, the desired position in the key dimensions and a key value scalar or sequence of the same length as the existing keys.

Parameters#

dimension

Dimension or dimension spec to add

dim_posint

Integer index to insert dimension at

dim_valscalar or ndarray

Dimension value(s) to add

vdim

Disabled, this type does not have value dimensions

**kwargs

Keyword arguments passed to the cloned element

Returns#

Cloned object containing the new dimension

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

Clones the object, overriding data and parameters.

Parameters#

data

New data replacing the existing data

shared_databool, optional

Whether to use existing data

new_typeoptional

Type to cast object to

linkbool, optional

Whether clone should be linked Determines whether Streams and Links attached to original object will be inherited.

*args

Additional arguments to pass to constructor

**overrides

New keyword arguments to pass to constructor

Returns#

Cloned object

collate()[source]#

Unpacks DynamicMap into container of DynamicMaps

Collation allows unpacking DynamicMaps which return Layout, NdLayout or GridSpace objects into a single such object containing DynamicMaps. Assumes that the items in the layout or grid that is returned do not change.

Returns#

Collated container containing DynamicMaps

property current_key#

Returns the current key value.

decollate()[source]#

Packs DynamicMap of nested DynamicMaps into a single DynamicMap that returns a non-dynamic element

Decollation allows packing a DynamicMap of nested DynamicMaps into a single DynamicMap that returns a simple (non-dynamic) element. All nested streams are lifted to the resulting DynamicMap, and are available in the streams property. The callback property of the resulting DynamicMap is a pure, stateless function of the stream values. To avoid stream parameter name conflicts, the resulting DynamicMap is configured with positional_stream_args=True, and the callback function accepts stream values as positional dict arguments.

Returns#

DynamicMap that returns a non-dynamic element

drop_dimension(dimensions)[source]#

Drops dimension(s) from keys

Parameters#

dimensions

Dimension(s) to drop

Returns#

Clone of object with with dropped dimension(s)

event(**kwargs)[source]#

Updates attached streams and triggers events

Automatically find streams matching the supplied kwargs to update and trigger events on them.

Parameters#

**kwargs

Events to update streams with

grid(dimensions=None, **kwargs)[source]#

Groups data by supplied dimension(s) laying the groups along the dimension(s) out in a GridSpace.

Parameters#

dimensionsDimension/str or list

Dimension or list of dimensions to group by

Returns#

gridGridSpace

GridSpace with supplied dimensions

groupby(dimensions=None, container_type=None, group_type=None, **kwargs)[source]#

Groups DynamicMap by one or more dimensions

Applies groupby operation over the specified dimensions returning an object of type container_type (expected to be dictionary-like) containing the groups.

Parameters#

dimensions : Dimension(s) to group by container_type : Type to cast group container to group_type : Type to cast each group to dynamic : Whether to return a DynamicMap **kwargs: Keyword arguments to pass to each group

Returns#

Returns object of supplied container_type containing the groups. If dynamic=True returns a DynamicMap instead.

hist(dimension=None, num_bins=20, bin_range=None, adjoin=True, **kwargs)[source]#

Computes and adjoins histogram along specified dimension(s).

Defaults to first value dimension if present otherwise falls back to first key dimension.

Parameters#

dimension : Dimension(s) to compute histogram on num_bins : int, optional

Number of bins

bin_rangetuple, optional

Lower and upper bounds of bins

adjoinbool, optional

Whether to adjoin histogram

Returns#

AdjointLayout of DynamicMap and adjoined histogram if adjoin=True, otherwise just the histogram

layout(dimensions=None, **kwargs)[source]#

Groups data by supplied dimension(s) laying the groups along the dimension(s) out in a NdLayout.

Parameters#

dimensionsDimension/str or list

Dimension or list of dimensions to group by

Returns#

layoutNdLayout

NdLayout with supplied dimensions

map(map_fn, specs=None, clone=True, link_inputs=True)[source]#

Map a function to all objects matching the specs

Recursively replaces elements using a map function when the specs apply, by default applies to all objects, e.g. to apply the function to all contained Curve objects:

dmap.map(fn, hv.Curve)

Parameters#

map_fn : Function to apply to each object specs : List of specs to match

List of types, functions or type[.group][.label] specs to select objects to return, by default applies to all objects.

clone : Whether to clone the object or transform inplace

Returns#

Returns the object after the map_fn has been applied

options(*args, **kwargs)[source]#

Applies simplified option definition returning a new object.

Applies options defined in a flat format to the objects returned by the DynamicMap. If the options are to be set directly on the objects returned by the DynamicMap a simple format may be used, e.g.:

obj.options(cmap=’viridis’, show_title=False)

If the object is nested the options must be qualified using a type[.group][.label] specification, e.g.:

obj.options(‘Image’, cmap=’viridis’, show_title=False)

or using:

obj.options({‘Image’: dict(cmap=’viridis’, show_title=False)})

Parameters#

*args

Sets of options to apply to object Supports a number of formats including lists of Options objects, a type[.group][.label] followed by a set of keyword options to apply and a dictionary indexed by type[.group][.label] specs.

backendoptional

Backend to apply options to Defaults to current selected backend

clonebool, optional

Whether to clone object Options can be applied inplace with clone=False

**kwargs

Keywords of options Set of options to apply to the object

Returns#

Returns the cloned object with the options applied

overlay(dimensions=None, **kwargs)[source]#

Group by supplied dimension(s) and overlay each group

Groups data by supplied dimension(s) overlaying the groups along the dimension(s).

Parameters#

dimensions : Dimension(s) of dimensions to group by

Returns#

NdOverlay object(s) with supplied dimensions

reindex(kdims=None, force=False)[source]#

Reorders key dimensions on DynamicMap

Create a new object with a reordered set of key dimensions. Dropping dimensions is not allowed on a DynamicMap.

Parameters#

kdims : List of dimensions to reindex the mapping with force : Not applicable to a DynamicMap

Returns#

Reindexed DynamicMap

relabel(label=None, group=None, depth=1)[source]#

Clone object and apply new group and/or label.

Applies relabeling to children up to the supplied depth.

Parameters#

labelstr, optional

New label to apply to returned object

groupstr, optional

New group to apply to returned object

depthint, optional

Depth to which relabel will be applied If applied to container allows applying relabeling to contained objects up to the specified depth

Returns#

Returns relabelled object

reset()[source]#

Clear the DynamicMap cache

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

Applies selection by dimension name

Applies a selection along the dimensions of the object using keyword arguments. The selection may be narrowed to certain objects using selection_specs. For container objects the selection will be applied to all children as well.

Selections may select a specific value, slice or set of values:

  • value: Scalar values will select rows along with an exact

    match, e.g.:

    ds.select(x=3)

  • slice: Slices may be declared as tuples of the upper and

    lower bound, e.g.:

    ds.select(x=(0, 3))

  • values: A list of values may be selected using a list or

    set, e.g.:

    ds.select(x=[0, 1, 2])

Parameters#

selection_specsList of specs to match on

A list of types, functions, or type[.group][.label] strings specifying which objects to apply the selection on.

**selection: Dictionary declaring selections by dimension

Selections can be scalar values, tuple ranges, lists of discrete values and boolean arrays

Returns#

Returns an Dimensioned object containing the selected data or a scalar if a single value was selected

property unbounded#

Returns a list of key dimensions that are unbounded, excluding stream parameters. If any of these key dimensions are unbounded, the DynamicMap as a whole is also unbounded.

class holoviews.core.spaces.Generator(callable, **params)[source]#

Bases: Callable

Generators are considered a special case of Callable that accept no arguments and never memoize.

Parameter Definitions


Parameters inherited from:

holoviews.core.spaces.Callable: inputs, operation_kwargs, link_inputs, memoize, operation, stream_mapping

callable = ClassSelector(allow_None=True, class_=<class 'generator'>, constant=True, label='Callable')

The generator that is wrapped by this Generator.

class holoviews.core.spaces.GridMatrix(initial_items=None, kdims=None, **params)[source]#

Bases: GridSpace

GridMatrix is container type for heterogeneous Element types laid out in a grid. Unlike a GridSpace the axes of the Grid must not represent an actual coordinate space, but may be used to plot various dimensions against each other. The GridMatrix is usually constructed using the gridmatrix operation, which will generate a GridMatrix plotting each dimension in an Element against each other.

Parameter Definitions


Parameters inherited from:

class holoviews.core.spaces.GridSpace(initial_items=None, kdims=None, **params)[source]#

Bases: Layoutable, UniformNdMapping

Grids are distinct from Layouts as they ensure all contained elements to be of the same type. Unlike Layouts, which have integer keys, Grids usually have floating point keys, which correspond to a grid sampling in some two-dimensional space. This two-dimensional space may have to arbitrary dimensions, e.g. for 2D parameter spaces.

Parameter Definitions


Parameters inherited from:

kdims = List(bounds=(1, 2), 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.

decollate()[source]#

Packs GridSpace of DynamicMaps into a single DynamicMap that returns a GridSpace

Decollation allows packing a GridSpace of DynamicMaps into a single DynamicMap that returns a GridSpace of simple (non-dynamic) elements. All nested streams are lifted to the resulting DynamicMap, and are available in the streams property. The callback property of the resulting DynamicMap is a pure, stateless function of the stream values. To avoid stream parameter name conflicts, the resulting DynamicMap is configured with positional_stream_args=True, and the callback function accepts stream values as positional dict arguments.

Returns#

DynamicMap that returns a GridSpace

keys(full_grid=False)[source]#

Returns the keys of the GridSpace

Parameters#

full_gridbool, optional

Return full cross-product of keys

Returns#

List of keys

property last#

The last of a GridSpace is another GridSpace constituted of the last of the individual elements. To access the elements by their X,Y position, either index the position directly or use the items() method.

property shape#

Returns the 2D shape of the GridSpace as (rows, cols).

class holoviews.core.spaces.HoloMap(initial_items=None, kdims=None, group=None, label=None, **params)[source]#

Bases: Layoutable, UniformNdMapping, Overlayable

A HoloMap is an n-dimensional mapping of viewable elements or overlays. Each item in a HoloMap has an tuple key defining the values along each of the declared key dimensions, defining the discretely sampled space of values.

The visual representation of a HoloMap consists of the viewable objects inside the HoloMap which can be explored by varying one or more widgets mapping onto the key dimensions of the HoloMap.

Parameter Definitions


Parameters inherited from:

collate(merge_type=None, drop=None, drop_constant=False)[source]#

Collate allows reordering nested containers

Collation allows collapsing nested mapping types by merging their dimensions. In simple terms in merges nested containers into a single merged type.

In the simple case a HoloMap containing other HoloMaps can easily be joined in this way. However collation is particularly useful when the objects being joined are deeply nested, e.g. you want to join multiple Layouts recorded at different times, collation will return one Layout containing HoloMaps indexed by Time. Changing the merge_type will allow merging the outer Dimension into any other UniformNdMapping type.

Parameters#

merge_type

Type of the object to merge with

drop

List of dimensions to drop

drop_constant

Drop constant dimensions automatically

Returns#

Collated Layout or HoloMap

decollate()[source]#

Packs HoloMap of DynamicMaps into a single DynamicMap that returns an HoloMap

Decollation allows packing a HoloMap of DynamicMaps into a single DynamicMap that returns an HoloMap of simple (non-dynamic) elements. All nested streams are lifted to the resulting DynamicMap, and are available in the streams property. The callback property of the resulting DynamicMap is a pure, stateless function of the stream values. To avoid stream parameter name conflicts, the resulting DynamicMap is configured with positional_stream_args=True, and the callback function accepts stream values as positional dict arguments.

Returns#

DynamicMap that returns an HoloMap

grid(dimensions=None, **kwargs)[source]#

Group by supplied dimension(s) and lay out groups in grid

Groups data by supplied dimension(s) laying the groups along the dimension(s) out in a GridSpace.

Parameters#

dimensionsDimension/str or list

Dimension or list of dimensions to group by

Returns#

GridSpace with supplied dimensions

hist(dimension=None, num_bins=20, bin_range=None, adjoin=True, individually=True, **kwargs)[source]#

Computes and adjoins histogram along specified dimension(s).

Defaults to first value dimension if present otherwise falls back to first key dimension.

Parameters#

dimension

Dimension(s) to compute histogram on

num_binsint, optional

Number of bins

bin_rangetuple, optional

Lower and upper bounds of bins

adjoinbool, optional

Whether to adjoin histogram

Returns#

AdjointLayout of HoloMap and histograms or just the histograms

layout(dimensions=None, **kwargs)[source]#

Group by supplied dimension(s) and lay out groups

Groups data by supplied dimension(s) laying the groups along the dimension(s) out in a NdLayout.

Parameters#

dimensions

Dimension(s) to group by

Returns#

NdLayout with supplied dimensions

options(*args, **kwargs)[source]#

Applies simplified option definition returning a new object

Applies options defined in a flat format to the objects returned by the DynamicMap. If the options are to be set directly on the objects in the HoloMap a simple format may be used, e.g.:

obj.options(cmap=’viridis’, show_title=False)

If the object is nested the options must be qualified using a type[.group][.label] specification, e.g.:

obj.options(‘Image’, cmap=’viridis’, show_title=False)

or using:

obj.options({‘Image’: dict(cmap=’viridis’, show_title=False)})

Parameters#

*args

Sets of options to apply to object Supports a number of formats including lists of Options objects, a type[.group][.label] followed by a set of keyword options to apply and a dictionary indexed by type[.group][.label] specs.

backendoptional

Backend to apply options to Defaults to current selected backend

clonebool, optional

Whether to clone object Options can be applied inplace with clone=False

**kwargs: Keywords of options

Set of options to apply to the object

Returns#

Returns the cloned object with the options applied

overlay(dimensions=None, **kwargs)[source]#

Group by supplied dimension(s) and overlay each group

Groups data by supplied dimension(s) overlaying the groups along the dimension(s).

Parameters#

dimensions

Dimension(s) of dimensions to group by

Returns#

NdOverlay object(s) with supplied dimensions

relabel(label=None, group=None, depth=1)[source]#

Clone object and apply new group and/or label.

Applies relabeling to children up to the supplied depth.

Parameters#

labelstr, optional

New label to apply to returned object

groupstr, optional

New group to apply to returned object

depthint, optional

Depth to which relabel will be applied If applied to container allows applying relabeling to contained objects up to the specified depth

Returns#

Returns relabelled object

holoviews.core.spaces.dynamicmap_memoization(callable_obj, streams)[source]#

Determine whether the Callable should have memoization enabled based on the supplied streams (typically by a DynamicMap). Memoization is disabled if any of the streams require it it and are currently in a triggered state.

holoviews.core.spaces.get_nested_dmaps(dmap)[source]#

Recurses DynamicMap to find DynamicMaps inputs

Parameters#

dmap

DynamicMap to recurse to look for DynamicMap inputs

Returns#

List of DynamicMap instances that were found

holoviews.core.spaces.get_nested_streams(dmap)[source]#

Recurses supplied DynamicMap to find all streams

Parameters#

dmap

DynamicMap to recurse to look for streams

Returns#

List of streams that were found

class holoviews.core.spaces.periodic(dmap)[source]#

Bases: object

Implements the utility of the same name on DynamicMap.

Used to defined periodic event updates that can be started and stopped.

stop()[source]#

Stop the periodic process.