On Mon, Dec 14, 2009 at 7:22 PM, nbv4 <cp3...@oh...> wrote:
>
> The histogram example in the matpolotlib gallery is just what I want, except
> instead of "probility" shown on the Y-axis, I want the number of items that
> fall into each bin to be plotted. How do I do this? Here is my code:
>
> import numpy as np
> import matplotlib
> matplotlib.use('Agg')
> import matplotlib.pyplot as plt
>
> fig = plt.figure()
> ax = fig.add_subplot(111)
>
> x = self.data ## a list, such as [12.43, 34.24, 35.56, 465.3547, ]
> ax.hist(x, 60, normed=1, facecolor='green', alpha=0.75)
>From the docstring for ax.hist:
*normed*:
If *True*, the first element of the return tuple will
be the counts normalized to form a probability density, i.e.,
``n/(len(x)*dbin)``. In a probability density, the integral of
the histogram should be 1; you can verify that with a
trapezoidal integration of the probability density function::
pdf, bins, patches = ax.hist(...)
print np.sum(pdf * np.diff(bins))
So instead, pass normed=False (instead of normed=1) to the call to ax.hist.
Ryan
--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
|