Points#

Download this notebook from GitHub (right-click to download).


Title
Points Element
Dependencies
Matplotlib
Backends
Matplotlib
Bokeh
Plotly
import numpy as np
import holoviews as hv
from holoviews import dim, opts

hv.extension('matplotlib')

The Points element visualizes as markers placed in a space of two independent variables, traditionally denoted x and y. In HoloViews, the names 'x' and 'y' are used as the default key dimensions (kdims) of the element. We can see this from the default axis labels when visualizing a simple Points element:

np.random.seed(12)
coords = np.random.rand(50,2)
points = hv.Points(coords)

points.opts(color='k', marker='+', s=50)

Here the random x values and random y values are both considered to be the coordinates, with no dependency between them (compare this to the different way that Scatter elements are defined). You can think of Points as simply marking positions in some two-dimensional space. Such positions can be sliced by specifying a 2D region of interest:

points + points[0.6:0.8,0.2:0.5]

Although the simplest Points element simply marks positions in a two-dimensional space without any associated value, value dimensions (vdims) are also supported. Here is an example with two additional quantities for each point, declared as the vdimss z and size (visualized as the color and size of the dots, respectively):

np.random.seed(10)
data = np.random.rand(100,4)

points = hv.Points(data, vdims=['z', 'size'])
(points + points[0.3:0.7, 0.3:0.7].hist()).opts(
    opts.Points(color='z', s=dim('size')*50))

In the right subplot, the hist method is used to show the distribution of samples along the first value dimension we added (z).

The marker shape specified above can be any supported by matplotlib, e.g. s, d, or o; the other options select the color and size of the marker. For convenience with the bokeh backend, the matplotlib marker options are supported using a compatibility function in HoloViews.

Note: Although the Scatter element is superficially similar to the Points element (they can generate plots that look identical), the two element types are semantically quite different. The fundamental difference is that Scatter is used to visualize data where the y variable is dependent, unlike Points. This semantic difference also explains why the histogram generated by the hist call above visualizes the distribution of a different dimension than it does for Scatter (because here z, not y, is the first vdim).

This difference means that Points elements can most naturally overlay with other elements that express independent variables in two-dimensional space, such as Raster types like Image. Conversely, Scatter expresses a dependent relationship between x and y and thus most naturally overlays with Chart types such as Curve.

For full documentation and the available style and plot options, use hv.help(hv.Points).

This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.

Download this notebook from GitHub (right-click to download).