Indexing and Selecting Data ¶
As explained in the Building composite objects and Dimensioned Containers guides, HoloViews allows building up hierarchical containers that express the natural relationships between data items, in whatever multidimensional space best characterizes the application domain. Once your data is in such containers, individual visualizations are then made by choosing subregions of this multidimensional space, either smaller numeric ranges (as in cropping of photographic images), or lower-dimensional subsets (as in selecting frames from a movie, or a specific movie from a large library), or both (as in selecting a cropped version of a frame from a specific movie from a large library).
In this user guide, we show how to specify such selections, using five different (but related) operations that can act on an element
e
:
Operation | Example syntax | Description |
---|---|---|
indexing | e[5.5], e[3,5.5] | Selecting a single data value, returning one actual numerical value from the existing data |
slice | e[3:5.5], e[3:5.5,0:1] | Selecting a contiguous portion from an Element, returning the same type of Element |
sample |
e.sample(y=5.5),
e.sample((3,3)) |
Selecting one or more regularly spaced data values, returning a new type of Element |
select |
e.select(y=5.5),
e.select(y=(3,5.5)) |
More verbose notation covering all supported slice and index operations by dimension name. |
iloc |
e[2, :],
e[2:5, :] |
Indexes and slices by row and column tabular index supporting integer indexes, slices, lists and boolean indices. |
These operations are all concerned with selecting some subset of the data values, without combining across data values (e.g. averaging) or otherwise transforming the actual data. In the Tabular Data user guide we will look at additional operations on the data that reduce, summarize, or transform the data in other ways, in addition to the selections covered here.
We'll be going through each operation in detail and provide a visual illustration to help make the semantics of each operation clear. This user guide assumes that you are familiar with continuous and discrete coordinate systems, so please review our Continuous Coordinates guide if you have not done so already.
import numpy as np
import holoviews as hv
from holoviews import opts
hv.extension('bokeh', 'matplotlib')
opts.defaults(
opts.Bounds(line_width=2, color='red', axiswise=True),
opts.Image(cmap='Blues'),
opts.Points(size=8, padding=0.1),
opts.Text(text_font_size='16pt'), opts.Scatter(size=5))