Scatter#

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


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

hv.extension('plotly')

The Scatter element visualizes as markers placed in a space of one independent variable, traditionally denoted as 'x', against a dependent variable, traditionally denoted as 'y'. In HoloViews, the name 'x' is the default dimension name used in the key dimensions (kdims) and 'y' is the default dimension name used in the value dimensions (vdims). We can see this from the default axis labels when visualizing a simple Scatter element:

np.random.seed(42)
scatter = hv.Scatter(np.random.randn(20).cumsum(axis=0))

scatter.opts(color='black', size=10, marker='circle')

Here the random y values are considered to be the ‘data’ whereas the x positions express where those data values were measured (compare this to the different way that Points elements are defined). In this sense, Scatter is equivalent to a Curve without any lines connecting the samples, and you can use slicing to view the y values corresponding to a chosen x range:

(scatter[0:12] + scatter[12:20])

A Scatter element must always have at least one value dimension (to give it a y location), but additional value dimensions are also supported. Here is an example with two additional quantities for each point, declared as the vdims 'z' and 'size' visualized as the color and size of the dots, respectively:

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

scatter = hv.Scatter(data, vdims=['y', 'z', 'size'])
(scatter + scatter[0.3:0.7, 0.3:0.7].hist()).opts(
    opts.Scatter(color='z', size=dim('size')*10))

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: Unlike Scatter, Points are used to visualize data where the y variable is independent. 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 Points (because here y, not z, is the first vdim).

This difference means that Scatter elements can most naturally overlay with other elements that express dependent relationships between the x and y axes in two-dimensional space, such as the Chart types like Curve. Conversely, Points elements either capture (x,y) spatial locations or they express a dependent relationship between an (x,y) location and some other dimension (expressed as point size, color, etc.), and thus they can most naturally overlay with Raster types like Image.

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

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).