[SciPy-user] Draw a density line on an histogram
Fri Jan 25 13:01:35 CST 2008
Charles Vejnar wrote:
> I have a series of numbers, and I want to have an idea about their
> distribution. I start with drawing an histogram with matplotlib.
> But I would like to have a curve (a "smooth histogram") representing the
> density (which is not a usual function).
> Something with kernel density estimates should be possible. Do you have any
> idea ?
In : from numpy import *
In : from scipy.stats import gaussian_kde
In : d = random.standard_normal(1000)
In : k = gaussian_kde(d)
In : d.min(), d.max()
Out: (-2.7279408369776075, 3.210698358446658)
In : x = linspace(-3.5, 3.5, 100)
In : y = k(x)
Now plot y versus x.
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the SciPy-user