holoviews.util Package¶
util
Package¶
-
class
holoviews.util.
Dynamic
(*args, **params)[source]¶ Bases:
param.parameterized.ParameterizedFunction
Dynamically applies a callable to the Elements in any HoloViews object. Will return a DynamicMap wrapping the original map object, which will lazily evaluate when a key is requested. By default Dynamic applies a no-op, making it useful for converting HoloMaps to a DynamicMap.
Any supplied kwargs will be passed to the callable and any streams will be instantiated on the returned DynamicMap. If the supplied operation is a method on a parameterized object which was decorated with parameter dependencies Dynamic will automatically create a stream to watch the parameter changes. This default behavior may be disabled by setting watch=False.
operation
= param.Callable()Operation or user-defined callable to apply dynamically
kwargs
= param.Dict(class_=<class ‘dict’>, default={})Keyword arguments passed to the function.
link_inputs
= param.Boolean(bounds=(0, 1), default=True)If Dynamic is applied to another DynamicMap, determines whether linked streams attached to its Callable inputs are transferred to the output of the utility. For example if the Dynamic utility is applied to a DynamicMap with an RangeXY, this switch determines whether the corresponding visualization should update this stream with range changes originating from the newly generated axes.
link_dataset
= param.Boolean(bounds=(0, 1), default=True)Determines whether the output of the operation should inherit the .dataset property of the input to the operation. Helpful for tracking data providence for user supplied functions, which do not make use of the clone method. Should be disabled for operations where the output is not derived from the input and instead depends on some external state.
shared_data
= param.Boolean(bounds=(0, 1), default=False)Whether the cloned DynamicMap will share the same cache.
streams
= param.List(bounds=(0, None), default=[])List of streams to attach to the returned DynamicMap
-
instance
(**params)¶ Return an instance of this class, copying parameters from any existing instance provided.
-
pprint
(imports=None, prefix='\n ', unknown_value='<?>', qualify=False, separator='')¶ Same as Parameterized.pprint, except that X.classname(Y is replaced with X.classname.instance(Y
-
script_repr
(imports=[], prefix=' ')¶ Same as Parameterized.script_repr, except that X.classname(Y is replaced with X.classname.instance(Y
-
holoviews.util.
examples
(path='holoviews-examples', verbose=False, force=False, root='/home/travis/build/holoviz/holoviews/holoviews/util/__init__.py')[source]¶ Copies the notebooks to the supplied path.
-
class
holoviews.util.
extension
(*args, **params)[source]¶ Bases:
pyviz_comms.extension
Helper utility used to load holoviews extensions. These can be plotting extensions, element extensions or anything else that can be registered to work with HoloViews.
-
instance
(**params)¶ Return an instance of this class, copying parameters from any existing instance provided.
-
pprint
(imports=None, prefix='\n ', unknown_value='<?>', qualify=False, separator='')¶ Same as Parameterized.pprint, except that X.classname(Y is replaced with X.classname.instance(Y
-
classmethod
register_backend_callback
(backend, callback)[source]¶ Registers a hook which is run when a backend is loaded
-
script_repr
(imports=[], prefix=' ')¶ Same as Parameterized.script_repr, except that X.classname(Y is replaced with X.classname.instance(Y
-
-
class
holoviews.util.
opts
(*args, **params)[source]¶ Bases:
param.parameterized.ParameterizedFunction
Utility function to set options at the global level or to provide an Options object that can be used with the .options method of an element or container.
Option objects can be generated and validated in a tab-completable way (in appropriate environments such as Jupyter notebooks) using completers such as opts.Curve, opts.Image, opts.Overlay, etc.
To set opts globally you can pass these option objects into opts.defaults:
opts.defaults(*options)
For instance:
opts.defaults(opts.Curve(color=’red’))
To set opts on a specific object, you can supply these option objects to the .options method.
For instance:
curve = hv.Curve([1,2,3]) curve.options(opts.Curve(color=’red’))
The options method also accepts lists of Option objects.
strict
= param.Boolean(bounds=(0, 1), default=False)Whether to be strict about the options specification. If not set to strict (default), any invalid keywords are simply skipped. If strict, invalid keywords prevent the options being applied.
-
classmethod
apply_groups
(obj, options=None, backend=None, clone=True, **kwargs)[source]¶ Applies nested options definition grouped by type.
Applies options on an object or nested group of objects, returning a new object with the options applied. This method accepts the separate option namespaces explicitly (i.e ‘plot’, ‘style’ and ‘norm’).
If the options are to be set directly on the object a simple format may be used, e.g.:
- opts.apply_groups(obj, style={‘cmap’: ‘viridis’},
plot={‘show_title’: False})
If the object is nested the options must be qualified using a type[.group][.label] specification, e.g.:
- opts.apply_groups(obj, {‘Image’: {‘plot’: {‘show_title’: False},
‘style’: {‘cmap’: ‘viridis}}})
If no opts are supplied all options on the object will be reset.
- Args:
- options (dict): Options specification
Options specification should be indexed by type[.group][.label] or option type (‘plot’, ‘style’, ‘norm’).
- backend (optional): Backend to apply options to
Defaults to current selected backend
- clone (bool, optional): Whether to clone object
Options can be applied inplace with clone=False
- **kwargs: Keywords of options by type
Applies options directly to the object by type (e.g. ‘plot’, ‘style’, ‘norm’) specified as dictionaries.
- Returns:
Returns the object or a clone with the options applied
-
classmethod
defaults
(*options, **kwargs)[source]¶ Set default options for a session.
Set default options for a session. whether in a Python script or a Jupyter notebook.
- Args:
*options: Option objects used to specify the defaults. backend: The plotting extension the options apply to
-
instance
(**params)¶ Return an instance of this class, copying parameters from any existing instance provided.
-
pprint
(imports=None, prefix='\n ', unknown_value='<?>', qualify=False, separator='')¶ Same as Parameterized.pprint, except that X.classname(Y is replaced with X.classname.instance(Y
-
script_repr
(imports=[], prefix=' ')¶ Same as Parameterized.script_repr, except that X.classname(Y is replaced with X.classname.instance(Y
-
class
holoviews.util.
output
(*args, **params)[source]¶ Bases:
param.parameterized.ParameterizedFunction
Helper used to set HoloViews display options. Arguments are supplied as a series of keywords in any order:
backend : The backend used by HoloViews fig : The static figure format holomap : The display type for holomaps widgets : The widget mode for widgets fps : The frames per second used for animations max_frames : The max number of frames rendered (default 500) size : The percentage size of displayed output dpi : The rendered dpi of the figure filename : The filename of the saved output, if any (default None) info : The information to page about the displayed objects (default False) css : Optional css style attributes to apply to the figure image tag widget_location : The position of the widgets relative to the plot
-
instance
(**params)¶ Return an instance of this class, copying parameters from any existing instance provided.
-
pprint
(imports=None, prefix='\n ', unknown_value='<?>', qualify=False, separator='')¶ Same as Parameterized.pprint, except that X.classname(Y is replaced with X.classname.instance(Y
-
script_repr
(imports=[], prefix=' ')¶ Same as Parameterized.script_repr, except that X.classname(Y is replaced with X.classname.instance(Y
-
-
holoviews.util.
render
(obj, backend=None, **kwargs)[source]¶ Renders the HoloViews object to the corresponding object in the specified backend, e.g. a Matplotlib or Bokeh figure.
The backend defaults to the currently declared default backend. The resulting object can then be used with other objects in the specified backend. For instance, if you want to make a multi-part Bokeh figure using a plot type only available in HoloViews, you can use this function to return a Bokeh figure that you can use like any hand-constructed Bokeh figure in a Bokeh layout.
- obj: HoloViews object
The HoloViews object to render
- backend: string
A valid HoloViews rendering backend
- **kwargs: dict
Additional keyword arguments passed to the renderer, e.g. fps for animations
- renderered:
The rendered representation of the HoloViews object, e.g. if backend=’matplotlib’ a matplotlib Figure or FuncAnimation
-
holoviews.util.
renderer
(name)[source]¶ Helper utility to access the active renderer for a given extension.
-
holoviews.util.
save
(obj, filename, fmt='auto', backend=None, resources='cdn', toolbar=None, title=None, **kwargs)[source]¶ Saves the supplied object to file.
The available output formats depend on the backend being used. By default and if the filename is a string the output format will be inferred from the file extension. Otherwise an explicit format will need to be specified. For ambiguous file extensions such as html it may be necessary to specify an explicit fmt to override the default, e.g. in the case of ‘html’ output the widgets will default to fmt=’widgets’, which may be changed to scrubber widgets using fmt=’scrubber’.
- obj: HoloViews object
The HoloViews object to save to file
- filename: string or IO object
The filename or BytesIO/StringIO object to save to
- fmt: string
The format to save the object as, e.g. png, svg, html, or gif and if widgets are desired either ‘widgets’ or ‘scrubber’
- backend: string
A valid HoloViews rendering backend, e.g. bokeh or matplotlib
- resources: string or bokeh.resource.Resources
Bokeh resources used to load bokehJS components. Defaults to CDN, to embed resources inline for offline usage use ‘inline’ or bokeh.resources.INLINE.
- toolbar: bool or None
Whether to include toolbars in the exported plot. If None, display the toolbar unless fmt is png and backend is bokeh. If True, always include the toolbar. If False, do not include the toolbar.
- title: string
Custom title for exported HTML file
- **kwargs: dict
Additional keyword arguments passed to the renderer, e.g. fps for animations
command
Module¶
python -m holoviews.util.command Conversion_Example.ipynb OR holoviews Conversion_Example.ipynb
parser
Module¶
The magics offered by the HoloViews IPython extension are powerful and support rich, compositional specifications. To avoid the the brittle, convoluted code that results from trying to support the syntax in pure Python, this file defines suitable parsers using pyparsing that are cleaner and easier to understand.
Pyparsing is required by matplotlib and will therefore be available if HoloViews is being used in conjunction with matplotlib.
-
class
holoviews.util.parser.
CompositorSpec
[source]¶ Bases:
holoviews.util.parser.Parser
The syntax for defining a set of compositor is as follows:
[ mode op(spec) [settings] value ]+
The components are:
mode : Operation mode, either ‘data’ or ‘display’. group : Value identifier with capitalized initial letter. op : The name of the operation to apply. spec : Overlay specification of form (A * B) where A and B are
dotted path specifications.
- settingsOptional list of keyword arguments to be used as
parameters to the operation (in square brackets).
-
classmethod
collect_tokens
(parseresult, mode)¶ Collect the tokens from a (potentially) nested parse result.
-
classmethod
parse
(line, ns={})[source]¶ Parse compositor specifications, returning a list Compositors
-
classmethod
todict
(parseresult, mode='parens', ns={})¶ Helper function to return dictionary given the parse results from a pyparsing.nestedExpr object (containing keywords).
The ns is a dynamic namespace (typically the IPython Notebook namespace) used to update the class-level namespace.
-
class
holoviews.util.parser.
OptsSpec
[source]¶ Bases:
holoviews.util.parser.Parser
An OptsSpec is a string specification that describes an OptionTree. It is a list of tree path specifications (using dotted syntax) separated by keyword lists for any of the style, plotting or normalization options. These keyword lists are denoted ‘plot(..)’, ‘style(…)’ and ‘norm(…)’ respectively. These three groups may be specified even more concisely using keyword lists delimited by square brackets, parentheses and braces respectively. All these sets are optional and may be supplied in any order.
For instance, the following string:
Image (interpolation=None) plot(show_title=False) Curve style(color=’r’)
Would specify an OptionTree where Image has “interpolation=None” for style and ‘show_title=False’ for plot options. The Curve has a style set such that color=’r’.
The parser is fairly forgiving; commas between keywords are optional and additional spaces are often allowed. The only restriction is that keywords must be immediately followed by the ‘=’ sign (no space).
-
classmethod
apply_deprecations
(path)[source]¶ Convert any potentially deprecated paths and issue appropriate warnings
-
classmethod
collect_tokens
(parseresult, mode)¶ Collect the tokens from a (potentially) nested parse result.
-
classmethod
parse
(line, ns={})[source]¶ Parse an options specification, returning a dictionary with path keys and {‘plot’:<options>, ‘style’:<options>} values.
-
classmethod
parse_options
(line, ns={})[source]¶ Similar to parse but returns a list of Options objects instead of the dictionary format.
-
classmethod
process_normalization
(parse_group)[source]¶ Given a normalization parse group (i.e. the contents of the braces), validate the option list and compute the appropriate integer value for the normalization plotting option.
-
classmethod
todict
(parseresult, mode='parens', ns={})¶ Helper function to return dictionary given the parse results from a pyparsing.nestedExpr object (containing keywords).
The ns is a dynamic namespace (typically the IPython Notebook namespace) used to update the class-level namespace.
-
classmethod
settings
Module¶
-
class
holoviews.util.settings.
KeywordSettings
[source]¶ Bases:
object
Base class for options settings used to specified collections of keyword options.
-
classmethod
extract_keywords
(line, items)[source]¶ Given the keyword string, parse a dictionary of options.
-
classmethod
-
class
holoviews.util.settings.
OutputSettings
[source]¶ Bases:
holoviews.util.settings.KeywordSettings
Class for controlling display and output settings.
-
classmethod
extract_keywords
(line, items)¶ Given the keyword string, parse a dictionary of options.
-
classmethod
get_options
(items, options, warnfn)¶ Given a keyword specification, validate and compute options
-
classmethod
transform
Module¶
-
class
holoviews.util.transform.
df_dim
(obj, *args, **kwargs)[source]¶ Bases:
holoviews.util.transform.dim
A subclass of dim which provides access to the DataFrame namespace along with tab-completion and type coercion allowing the expression to be applied on any columnar dataset.
-
applies
(dataset, strict=False)¶ Determines whether the dim transform can be applied to the Dataset, i.e. whether all referenced dimensions can be resolved.
-
apply
(dataset, flat=False, expanded=None, ranges={}, all_values=False, keep_index=False, compute=True, strict=False)¶ Evaluates the transform on the supplied dataset.
- Args:
dataset: Dataset object to evaluate the expression on flat: Whether to flatten the returned array expanded: Whether to use the expanded expand values ranges: Dictionary for ranges for normalization all_values: Whether to evaluate on all values
Whether to evaluate on all available values, for some element types, such as Graphs, this may include values not included in the referenced column
- keep_index: For data types that support indexes, whether the index
should be preserved in the result.
- compute: For data types that support lazy evaluation, whether
the result should be computed before it is returned.
- strict: Whether to strictly check for dimension matches
(if False, counts any dimensions with matching names as the same)
- Returns:
values: NumPy array computed by evaluating the expression
-
bin
(bins, labels=None)¶ Bins continuous values.
Bins continuous using the provided bins and assigns labels either computed from each bins center point or from the supplied labels.
- Args:
bins: List or array containing the bin boundaries labels: List of labels to assign to each bin
If the bins are length N the labels should be length N-1
-
categorize
(categories, default=None)¶ Replaces discrete values with supplied categories
Replaces discrete values in input array into a fixed set of categories defined either as a list or dictionary.
- Args:
categories: List or dict of categories to map inputs to default: Default value to assign if value not in categories
-
clone
(dimension=None, ops=None, dim_type=None)¶ Creates a clone of the dim expression optionally overriding the dim and ops.
-
lognorm
(limits=None)¶ - Unity-based normalization log scale.
Apply the same transformation as matplotlib.colors.LogNorm
- Args:
limits: tuple of (min, max) defining the normalization range
-
norm
(limits=None)¶ Unity-based normalization to scale data into 0-1 range.
(values - min) / (max - min)
- Args:
limits: tuple of (min, max) defining the normalization range
-
classmethod
pipe
(func, *args, **kwargs)¶ Wrapper to give multidimensional transforms a more intuitive syntax. For a custom function ‘func’ with signature (*args, **kwargs), call as dim.pipe(func, *args, **kwargs).
-
classmethod
register
(key, function)¶ Register a custom dim transform function which can from then on be referenced by the key.
-
property
str
¶ Casts values to strings or provides str accessor.
-
-
class
holoviews.util.transform.
dim
(obj, *args, **kwargs)[source]¶ Bases:
object
dim transform objects are a way to express deferred transforms on Datasets. dim transforms support all mathematical and bitwise operators, NumPy ufuncs and methods, and provide a number of useful methods for normalizing, binning and categorizing data.
-
applies
(dataset, strict=False)[source]¶ Determines whether the dim transform can be applied to the Dataset, i.e. whether all referenced dimensions can be resolved.
-
apply
(dataset, flat=False, expanded=None, ranges={}, all_values=False, keep_index=False, compute=True, strict=False)[source]¶ Evaluates the transform on the supplied dataset.
- Args:
dataset: Dataset object to evaluate the expression on flat: Whether to flatten the returned array expanded: Whether to use the expanded expand values ranges: Dictionary for ranges for normalization all_values: Whether to evaluate on all values
Whether to evaluate on all available values, for some element types, such as Graphs, this may include values not included in the referenced column
- keep_index: For data types that support indexes, whether the index
should be preserved in the result.
- compute: For data types that support lazy evaluation, whether
the result should be computed before it is returned.
- strict: Whether to strictly check for dimension matches
(if False, counts any dimensions with matching names as the same)
- Returns:
values: NumPy array computed by evaluating the expression
-
bin
(bins, labels=None)[source]¶ Bins continuous values.
Bins continuous using the provided bins and assigns labels either computed from each bins center point or from the supplied labels.
- Args:
bins: List or array containing the bin boundaries labels: List of labels to assign to each bin
If the bins are length N the labels should be length N-1
-
categorize
(categories, default=None)[source]¶ Replaces discrete values with supplied categories
Replaces discrete values in input array into a fixed set of categories defined either as a list or dictionary.
- Args:
categories: List or dict of categories to map inputs to default: Default value to assign if value not in categories
-
clone
(dimension=None, ops=None, dim_type=None)[source]¶ Creates a clone of the dim expression optionally overriding the dim and ops.
-
lognorm
(limits=None)[source]¶ - Unity-based normalization log scale.
Apply the same transformation as matplotlib.colors.LogNorm
- Args:
limits: tuple of (min, max) defining the normalization range
-
norm
(limits=None)[source]¶ Unity-based normalization to scale data into 0-1 range.
(values - min) / (max - min)
- Args:
limits: tuple of (min, max) defining the normalization range
-
classmethod
pipe
(func, *args, **kwargs)[source]¶ Wrapper to give multidimensional transforms a more intuitive syntax. For a custom function ‘func’ with signature (*args, **kwargs), call as dim.pipe(func, *args, **kwargs).
-
classmethod
register
(key, function)[source]¶ Register a custom dim transform function which can from then on be referenced by the key.
-
property
str
¶ Casts values to strings or provides str accessor.
-
-
class
holoviews.util.transform.
iloc
(dim_expr)[source]¶ Bases:
object
Implements integer array indexing for dim expressions.
-
holoviews.util.transform.
lognorm
(values, min=None, max=None)[source]¶ - Unity-based normalization on log scale.
Apply the same transformation as matplotlib.colors.LogNorm
- Args:
values: Array of values to be normalized min (float, optional): Lower bound of normalization range max (float, optional): Upper bound of normalization range
- Returns:
Array of normalized values
-
holoviews.util.transform.
norm
(values, min=None, max=None)[source]¶ Unity-based normalization to scale data into 0-1 range.
(values - min) / (max - min)
- Args:
values: Array of values to be normalized min (float, optional): Lower bound of normalization range max (float, optional): Upper bound of normalization range
- Returns:
Array of normalized values
-
class
holoviews.util.transform.
xr_dim
(obj, *args, **kwargs)[source]¶ Bases:
holoviews.util.transform.dim
A subclass of dim which provides access to the xarray DataArray namespace along with tab-completion and type coercion allowing the expression to be applied on any gridded dataset.
-
applies
(dataset, strict=False)¶ Determines whether the dim transform can be applied to the Dataset, i.e. whether all referenced dimensions can be resolved.
-
apply
(dataset, flat=False, expanded=None, ranges={}, all_values=False, keep_index=False, compute=True, strict=False)¶ Evaluates the transform on the supplied dataset.
- Args:
dataset: Dataset object to evaluate the expression on flat: Whether to flatten the returned array expanded: Whether to use the expanded expand values ranges: Dictionary for ranges for normalization all_values: Whether to evaluate on all values
Whether to evaluate on all available values, for some element types, such as Graphs, this may include values not included in the referenced column
- keep_index: For data types that support indexes, whether the index
should be preserved in the result.
- compute: For data types that support lazy evaluation, whether
the result should be computed before it is returned.
- strict: Whether to strictly check for dimension matches
(if False, counts any dimensions with matching names as the same)
- Returns:
values: NumPy array computed by evaluating the expression
-
bin
(bins, labels=None)¶ Bins continuous values.
Bins continuous using the provided bins and assigns labels either computed from each bins center point or from the supplied labels.
- Args:
bins: List or array containing the bin boundaries labels: List of labels to assign to each bin
If the bins are length N the labels should be length N-1
-
categorize
(categories, default=None)¶ Replaces discrete values with supplied categories
Replaces discrete values in input array into a fixed set of categories defined either as a list or dictionary.
- Args:
categories: List or dict of categories to map inputs to default: Default value to assign if value not in categories
-
clone
(dimension=None, ops=None, dim_type=None)¶ Creates a clone of the dim expression optionally overriding the dim and ops.
-
lognorm
(limits=None)¶ - Unity-based normalization log scale.
Apply the same transformation as matplotlib.colors.LogNorm
- Args:
limits: tuple of (min, max) defining the normalization range
-
norm
(limits=None)¶ Unity-based normalization to scale data into 0-1 range.
(values - min) / (max - min)
- Args:
limits: tuple of (min, max) defining the normalization range
-
classmethod
pipe
(func, *args, **kwargs)¶ Wrapper to give multidimensional transforms a more intuitive syntax. For a custom function ‘func’ with signature (*args, **kwargs), call as dim.pipe(func, *args, **kwargs).
-
classmethod
register
(key, function)¶ Register a custom dim transform function which can from then on be referenced by the key.
-
property
str
¶ Casts values to strings or provides str accessor.
-