Plotting histograms

Robert Kern robert.kern at
Tue Oct 17 06:00:51 CEST 2006

amitsoni.1984 at 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