Plotting histograms

amitsoni.1984 at gmail.com amitsoni.1984 at gmail.com
Wed Oct 18 02:01:08 EDT 2006


Thanks Robert,

My previous problem is solved(I was using 'from matplotlib.pylab import
*') but now I am facing another problem. I want to plot the histogram
of eigenvalues calculated and I am using the following code:
_______________________________________________________________________
import numpy
from matplotlib import pylab

n=100
ra = numpy.random
la = numpy.linalg

A = ra.standard_normal((n,n))
S = (A + numpy.transpose(A))/(2*n^(1/2))

eig = la.eigvals(S)

[N,x]=pylab.hist(eig, 10) # make a histogram
-------------------------------------------------------------------------------------------------------------

But again it is giving some error, which is given below:

File "C:\Documents and Settings\amitsoni\Desktop\New
Folder\wignerpython", line 15, in <module>
[N,x]=pylab.hist(eig, 10) # make a histogram
ValueError: too many values to unpack

Can anyone help me out with this??

Thanks
Amit

Robert Kern wrote:
> amitsoni.1984 at gmail.com wrote:
> > hi, I have some values(say from -a to a) stored in a vector and I want
> > to plot a histogram for those values. How can I get it done in python.
> > I have installed and imported the Matplotlib package but on executing
> > the code
> > [N,x]=hist(eig, 10) # make a histogram
> >  I am getting an error saying   "NameError: name 'hist' is not
> > defined".
>
> I presume what you did was something like this:
>
>    from matplotlib import pylab
>    [N,x] = hist(eig, 10)
>
> What you actually want is this:
>
>    from matplotlib import pylab
>    [N,x] = pylab.hist(eig, 10)
>
> Or, if you're at the interactive prompt (but remember that it is inadvisable to
> do so in modules):
>
>    from matplotlib.pylab import *
>    [N,x] = hist(eig, 10)
>
> You will probably want to review the section of the tutorial on importing
> modules if you don't understand the differences.
>
> --
> Robert Kern
>
> "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 Python-list mailing list