histogram examples?

Greetings. I need to make some histograms from within a Python program,
and I noticed that Matplotlib, which I've never used before, appears to
have that capability.

At:
    http://matplotlib.sourceforge.net/

I see the following simple example:

    >>> from pylab import randn, hist
    >>> x = randn(10000)
    >>> hist(x, 100)

And there is a more-extended example at:

http://matplotlib.sourceforge.net/_static/plot_directive/mpl_examples/pylab_examples/histogram_demo.py

Unfortunately, when I run either example I get nothing but complaints
and errors, as in the appended.

This is on a system running 64-bit Fedora 9 and Python 2.5.1.

I'm evidently doing something wrong. Will somebody please point me in
the right direction?

Thanks.

          - Mike

$ python
Python 2.5.1 (r251:54863, Jun 15 2008, 18:24:56)
[GCC 4.3.0 20080428 (Red Hat 4.3.0-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

from pylab import randn, hist
x = randn(10000)
hist(x, 100)

/usr/lib64/python2.5/site-packages/numpy/lib/function_base.py:343:
Warning:
            The semantics of histogram has been modified in
            the current release to fix long-standing issues with
            outliers handling. The main changes concern
            1. the definition of the bin edges,
               now including the rightmost edge, and
            2. the handling of upper outliers, now ignored rather
               than tallied in the rightmost bin.
            The previous behaviour is still accessible using
            `new=False`, but is scheduled to be deprecated in the
            next release (1.3).

            *This warning will not printed in the 1.3 release.*

            Use `new=True` to bypass this warning.

            Please read the docstring for more information.
            
  """, Warning)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.5/site-packages/matplotlib/pyplot.py", line
1633, in hist
    ret = gca().hist(*args, **kwargs)
  File "/usr/lib64/python2.5/site-packages/matplotlib/axes.py", line
5117, in hist
    n, bins = npy.histogram(x, bins, range=None, normed=normed)
TypeError: 'NoneType' object is not iterable

···

--
Michael Hannon mailto:hannon@…1477…
Dept. of Physics 530.752.4966
University of California 530.752.4717 FAX
Davis, CA 95616-8677

Michael Hannon wrote:

Greetings. I need to make some histograms from within a Python program,
and I noticed that Matplotlib, which I've never used before, appears to
have that capability.

At:
    http://matplotlib.sourceforge.net/

I see the following simple example:

    >>> from pylab import randn, hist
    >>> x = randn(10000)
    >>> hist(x, 100)

And there is a more-extended example at:

http://matplotlib.sourceforge.net/_static/plot_directive/mpl_examples/pylab_examples/histogram_demo.py

Unfortunately, when I run either example I get nothing but complaints
and errors, as in the appended.

This is on a system running 64-bit Fedora 9 and Python 2.5.1.

I'm evidently doing something wrong. Will somebody please point me in
the right direction?

It sounds like your matplotlib version is too old for your numpy version. What version of matplotlib are you using? Can you install a newer one, or, better yet, build from svn? (The warning from numpy is easy to deal with; the TypeError from matplotlib is what indicates that the version is incompatible.)

Eric

···

Thanks.

          - Mike

$ python
Python 2.5.1 (r251:54863, Jun 15 2008, 18:24:56) [GCC 4.3.0 20080428 (Red Hat 4.3.0-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

from pylab import randn, hist
x = randn(10000)
hist(x, 100)

/usr/lib64/python2.5/site-packages/numpy/lib/function_base.py:343:
Warning: The semantics of histogram has been modified in
            the current release to fix long-standing issues with
            outliers handling. The main changes concern
            1. the definition of the bin edges,
               now including the rightmost edge, and
            2. the handling of upper outliers, now ignored rather
               than tallied in the rightmost bin.
            The previous behaviour is still accessible using
            `new=False`, but is scheduled to be deprecated in the
            next release (1.3).

            *This warning will not printed in the 1.3 release.*

            Use `new=True` to bypass this warning.

            Please read the docstring for more information.
              """, Warning)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.5/site-packages/matplotlib/pyplot.py", line
1633, in hist
    ret = gca().hist(*args, **kwargs)
  File "/usr/lib64/python2.5/site-packages/matplotlib/axes.py", line
5117, in hist
    n, bins = npy.histogram(x, bins, range=None, normed=normed)
TypeError: 'NoneType' object is not iterable

Hi, Eric. I'm using the packages provided by Fedora:

    numpy.x86_64 1.2.0-1.fc9
    python-matplotlib.x86_64 0.91.4-1.fc9

It appears that numpy is reasonably up-to-date, but Matplotlib appears
to be relatively old (although I don't know what d(version)/dt is).

I'll look into installing from the source kits (and/or look into Fedora
10, which will be shipping in a couple of weeks, IIRC).

Thanks.

          - Mike

···

On Tue, Nov 11, 2008 at 07:13:46AM -1000, Eric Firing wrote:

Michael Hannon wrote:
>Greetings. I need to make some histograms from within a Python program,
>and I noticed that Matplotlib, which I've never used before, appears to
>have that capability.
>
>At:
> http://matplotlib.sourceforge.net/
>
>I see the following simple example:
>
> >>> from pylab import randn, hist
> >>> x = randn(10000)
> >>> hist(x, 100)
>
>And there is a more-extended example at:
>
>http://matplotlib.sourceforge.net/_static/plot_directive/mpl_examples/pylab_examples/histogram_demo.py
>
>Unfortunately, when I run either example I get nothing but complaints
>and errors, as in the appended.
>
>This is on a system running 64-bit Fedora 9 and Python 2.5.1.
>
>I'm evidently doing something wrong. Will somebody please point me in
>the right direction?

It sounds like your matplotlib version is too old for your numpy
version. What version of matplotlib are you using? Can you install a
newer one, or, better yet, build from svn? (The warning from numpy is
easy to deal with; the TypeError from matplotlib is what indicates that
the version is incompatible.)

Eric

--
Michael Hannon mailto:hannon@…1477…
Dept. of Physics 530.752.4966
University of California 530.752.4717 FAX
Davis, CA 95616-8677

Michael Hannon wrote:

Michael Hannon wrote:

Greetings. I need to make some histograms from within a Python program,
and I noticed that Matplotlib, which I've never used before, appears to
have that capability.

At:
   http://matplotlib.sourceforge.net/

I see the following simple example:

   >>> from pylab import randn, hist
   >>> x = randn(10000)
   >>> hist(x, 100)

And there is a more-extended example at:

http://matplotlib.sourceforge.net/_static/plot_directive/mpl_examples/pylab_examples/histogram_demo.py

Unfortunately, when I run either example I get nothing but complaints
and errors, as in the appended.

This is on a system running 64-bit Fedora 9 and Python 2.5.1.

I'm evidently doing something wrong. Will somebody please point me in
the right direction?

It sounds like your matplotlib version is too old for your numpy version. What version of matplotlib are you using? Can you install a newer one, or, better yet, build from svn? (The warning from numpy is easy to deal with; the TypeError from matplotlib is what indicates that the version is incompatible.)

Eric

Hi, Eric. I'm using the packages provided by Fedora:

    numpy.x86_64 1.2.0-1.fc9
    python-matplotlib.x86_64 0.91.4-1.fc9

It appears that numpy is reasonably up-to-date, but Matplotlib appears
to be relatively old (although I don't know what d(version)/dt is).

Yes, your numpy is fine, but your matplotlib is an older branch, and although it is still being maintained it looks like it is not in sync with changes to numpy going from 1.1 to 1.2. I hope Fedora 10 has switched to the current branch, 0.98.x. In any case, however, matplotlib changes fast enough that it may be worthwhile building your own. It is very easy to do on a linux machine once the necessary headers are in place. Typically this involves installing several *dev or *devel packages--I don't know the specifics of Fedora packaging.

Eric

···

On Tue, Nov 11, 2008 at 07:13:46AM -1000, Eric Firing wrote:

I'll look into installing from the source kits (and/or look into Fedora
10, which will be shipping in a couple of weeks, IIRC).

Thanks.

          - Mike

.
.
.

>Hi, Eric. I'm using the packages provided by Fedora:
>
> numpy.x86_64 1.2.0-1.fc9
> python-matplotlib.x86_64 0.91.4-1.fc9
>
>It appears that numpy is reasonably up-to-date, but Matplotlib appears
>to be relatively old (although I don't know what d(version)/dt is).

Yes, your numpy is fine, but your matplotlib is an older branch, and
although it is still being maintained it looks like it is not in sync
with changes to numpy going from 1.1 to 1.2. I hope Fedora 10 has
switched to the current branch, 0.98.x. In any case, however,
matplotlib changes fast enough that it may be worthwhile building your
own. It is very easy to do on a linux machine once the necessary
headers are in place. Typically this involves installing several *dev
or *devel packages--I don't know the specifics of Fedora packaging.

Thanks again, Eric. I built Matplotlib 0.98 from source on my Fedora
box, and that did fix the problem.

I haven't checked Fedora 10 yet (arriving in 13 days).

          - Mike

···

On Tue, Nov 11, 2008 at 08:52:15AM -1000, Eric Firing wrote:
--
Michael Hannon mailto:hannon@…1477…
Dept. of Physics 530.752.4966
University of California 530.752.4717 FAX
Davis, CA 95616-8677