Ben Chuanlong Du's Blog

It is never too late to learn.

Plot Histogram Using HoloViews

Reference

http://holoviews.org/reference/elements/bokeh/Histogram.html

Comments

  1. HoloViews.Histogram takes the output of np.histogram as input and generate a histogram plot.
In [11]:
import numpy as np
import holoviews as hv

hv.extension("bokeh")

Generate a histogram from a bunch of values.

In [12]:
np.random.seed(1)
data = np.random.randn(10000)
hist = np.histogram(data, 20)
hv.Histogram(hist)
Out[12]:

Multiple histograms on the same plot.

In [17]:
from bokeh.sampledata.autompg import autompg

autompg_ds = hv.Dataset(autompg)
In [18]:
%%opts Histogram (alpha=0.9) [width=600]
autompg_ds.hist(dimension='mpg', groupby='cyl', adjoin=False)
Out[18]:

Make Histogram From Frequencies and Edges

In [ ]:
np.random.seed(1)
data = np.random.randn(10000)
frequencies, edges = np.histogram(data, 20)
print("Values: %s, Edges: %s" % (frequencies.shape[0], edges.shape[0]))
hv.Histogram((edges, frequencies))

Comments