Re: Plotting histograms

2006-10-18 Thread [EMAIL PROTECTED]
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:
 [EMAIL PROTECTED] 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

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Plotting histograms

2006-10-18 Thread Robert Kern
[EMAIL PROTECTED] wrote:
 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))

Note that this line won't do what you think it does. First, one integer divided 
by another integer returns an integer, so (1/2) == 0. Also, ^ is not 
exponentiation but bitwise XOR. Use ** for exponentiation. However, in this 
case, you should use numpy.sqrt().

 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??

pylab.hist() does not return two values, it returns three. Sorry I didn't catch 
that earlier.

-- 
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

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Plotting histograms

2006-10-18 Thread Roberto Bonvallet
[EMAIL PROTECTED] 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.
 
 Is there any other way to plot histograms over a given range?

 # create random vector
... from random import randrange
 a = 5
 v = [randrange(-a, a+1) for i in xrange(100)]

 # print histogram
... for i in range(-a, a+1):
... print %+d %s % (i, '*' * v.count(i))
...
-5 *
-4 *
-3 *
-2 **
-1 **
+0 *
+1 
+2 ***
+3 *
+4 
+5 


:)
-- 
Roberto Bonvallet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Plotting histograms

2006-10-18 Thread [EMAIL PROTECTED]
Thanks for the replies  ... its perfect now ... but just one more thing
... how can I plot another function(a semi circle) in the same
histogram?

thanks

amit


Robert Kern wrote:
 [EMAIL PROTECTED] wrote:
  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))

 Note that this line won't do what you think it does. First, one integer 
 divided
 by another integer returns an integer, so (1/2) == 0. Also, ^ is not
 exponentiation but bitwise XOR. Use ** for exponentiation. However, in this
 case, you should use numpy.sqrt().

  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??

 pylab.hist() does not return two values, it returns three. Sorry I didn't 
 catch
 that earlier.

 --
 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 Ec

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Plotting histograms

2006-10-18 Thread Robert Kern
[EMAIL PROTECTED] wrote:
 Thanks for the replies  ... its perfect now ... but just one more thing
 ... how can I plot another function(a semi circle) in the same
 histogram?

Just call the appropriate plotting function after you plot the histogram. By 
default, the second plot will go into the same figure as the first. Something 
like the following should suffice:

   x = numpy.linspace(-1.0, 1.0, 201)
   y = numpy.sqrt(1.0 - x*x)
   pylab.plot(x, y, 'k-')

Look at the matplotlib documentation for more information. You will probably 
also want to ask future questions on the matplotlib-users mailing list instead 
of here.

-- 
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

-- 
http://mail.python.org/mailman/listinfo/python-list


pylab package dependencies (was: Plotting histograms)

2006-10-17 Thread Lou Pecora
In article [EMAIL PROTECTED],
 Robert Kern [EMAIL PROTECTED] wrote:

 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.


Is pylab part of matplotlib?  I always thought it was the other way 
around. I have a similar view of numpy as part of scipy.  Maybe I'm 
confused on the dependencies.  I find it confusing in the examples 
sometimes when the bigger package is imported (e.g. scipy) and then a 
subpackage is also imported.  Like this:

from scipi import *
from scipi import numpy

I know I've seen stuff like that, but I don't get it.  The dependencies 
are confusing to me.  

I did a search of the tutorial on 'import' but didn't find the answer.

-- Lou Pecora  (my views are my own) REMOVE THIS to email me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Plotting histograms

2006-10-16 Thread [EMAIL PROTECTED]
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.

Is there any other way to plot histograms over a given range?

thanks

Amit

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Plotting histograms

2006-10-16 Thread Robert Kern
[EMAIL PROTECTED] 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

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Plotting histograms

2006-10-16 Thread Theerasak Photha
On 16 Oct 2006 20:49:10 -0700, [EMAIL PROTECTED]
[EMAIL PROTECTED] 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.

Use the statement 'from pylab import *' in the beginning of your program.

Others, of course, may find it more tasteful and Pythonic to do:

[N,x]=pylab.hist(eig, 10)

i.e., prefix it with the package name. Wouldn't want to clutter the
global namespace of your program after all.

Good luck with it then. I think I see a reference to advanced linear
algebra with 'eig' (Eigen-?) and I'm sure you understand that better
than I. :)

-- Theerasak
-- 
http://mail.python.org/mailman/listinfo/python-list