import numpy as np import holoviews as hv hv.extension('matplotlib')
s partition the
axis into discrete (but not necessarily regular) bins, showing counts in each as a bar. A
accepts the output of
as input, which consists of a tuple of the histogram values with a shape of
and bin edges with a shape of
. As a simple example we will generate a histogram of a normal distribution with 20 bins.
np.random.seed(1) data = np.random.randn(10000) frequencies, edges = np.histogram(data, 20) print('Values: %s, Edges: %s' % (frequencies.shape, edges.shape)) hv.Histogram(frequencies, edges)
Values: 20, Edges: 21
Element will also expand evenly sampled bin centers, therefore we can easily cast between a linearly sampled Curve or Scatter and a Histogram.
xs = np.linspace(0, np.pi*2) ys = np.sin(xs) curve = hv.Curve((xs, ys)) curve + hv.Histogram(curve)
method is an easy way to compute a histogram from an existing Element. The method effectively just calls the
operation, which lets you compute a histogram from an Element, and then adjoins the resulting histogram. Here we will create two sets of
, compute a
for the 'x' and 'y' dimension on each, which we then overlay and adjoin to the plot.
%%opts Histogram (alpha=0.3) from holoviews.operation import histogram points1 = hv.Points(np.random.randn(100,2)*2+1) points2 = hv.Points(np.random.randn(100,2)) xhist, yhist = (histogram(points1, bin_range=(-5, 5), dimension=dim) * histogram(points2, bin_range=(-5, 5), dimension=dim) for dim in 'xy') (points1 * points2) << yhist(plot=dict(width=125)) << xhist(plot=dict(height=125))