[Numpy-discussion] NumPy Histogram for Tentative NumPy Tutorial Questions

josef.pktd@gmai... josef.pktd@gmai...
Thu Nov 26 14:23:06 CST 2009


On Thu, Nov 26, 2009 at 2:44 PM, Wayne Watson
<sierra_mtnview@sbcglobal.net> wrote:
> I decided to try some example code from Subject.
>
> import numpy
> import pylab
> # Build a vector of 10000 normal deviates with variance 0.5^2 and mean 2
> mu, sigma = 2, 0.5
> v = numpy.random.normal(mu,sigma,10000)
> # Plot a normalized histogram with 50 bins
> pylab.hist(v, bins=50, normed=1)       # matplotlib version (plot)
> pylab.show()
> # Compute the histogram with numpy and then plot it
> (n, bins) = numpy.histogram(v, bins=50, normed=1)  # NumPy version (no plot)
> pylab.plot(.5*(bins[1:]+bins[:-1]), n)
> pylab.show()
>
> After the histogram is displayed how do I get to the plot?
> Where is histogram described in some detail? Normalized?
> The histogram x-axis goes from 0 to 4.5. How does that happen?
> Is v is two dimensional? What if it's one dimensional?

some quick answers:

matlplotlib's histogram uses numpy histogram for the calculations,
options are pretty well explained  in the numpy docs, matplotlib has
docs and examples for the display.

If I use numpy.histogram, then, I think, I used bar plot for the
display (scipy.stats.tutorial might also have an example where I had
taken the pattern from somewhere else)

numpy also has 2d and multidimensional histogram, but I don't know if
the new 3d features of matplotlib can display them.

Josef

>
>
>
> --
>           Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
>
>             (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
>              Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet
>
>                   350 350 350 350 350 350 350 350 350 350
>                     Make the number famous. See 350.org
>            The major event has passed, but keep the number alive.
>
>                    Web Page: <www.speckledwithstars.net/>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the NumPy-Discussion mailing list