# hist doesn't work with 2D arrays

Hopefully this isn't old news for you. Since the 0.98 release, the histogram plot doesn't work properly with 2D arrays: it is quite slow and the output is wrong. Passing a flattened array produces the quick, correct output that we are accustomed to. Here is the test code I ran, and the attached image shows the output compared with the previous version.

import numpy as n
import matplotlib.pyplot as p

a = n.random.normal(size=10000)
a = a.reshape((100,100)) # make a 2D array of normally-distributed random numbers
p.hist(a)

Thanks for your work on matplotlib!

Andrew Hawryluk
<<hist-comparison.png>>

Andrew Hawryluk wrote:

Hopefully this isn't old news for you. Since the 0.98 release, the histogram plot doesn't work properly with 2D arrays: it is quite slow and the output is wrong. Passing a flattened array produces the quick, correct output that we are accustomed to. Here is the test code I ran, and the attached image shows the output compared with the previous version.

import numpy as n
import matplotlib.pyplot as p

a = n.random.normal(size=10000)
a = a.reshape((100,100)) # make a 2D array of normally-distributed random numbers
p.hist(a)

Thanks for your work on matplotlib!

Hi Andrew,
2D arrays are now treated differently. An (N,M) 2D array is interpreted as M data-sets with N elements each, e.g.

a = n.random.normal(size=10000)
a = a.reshape((1000,10))

is interpreted as 10 data-sets with 1000 elements each. See histogram_demo_extended.py in examples/pylab_examples.

To reproduce the old behaviour you should use pylab.hist(a.flat).

Manuel

···

Andrew Hawryluk
<<hist-comparison.png>>

------------------------------------------------------------------------

------------------------------------------------------------------------

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08

------------------------------------------------------------------------

_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
matplotlib-devel List Signup and Options

Ah - that makes sense. I guess I didn't catch that change in the release notes. Thanks again!

···

-----Original Message-----
From: Manuel Metz [mailto:mmetz@…459…]
Sent: 7 Jul 2008 11:49 AM
To: matplotlib-devel@lists.sourceforge.net
Cc: Andrew Hawryluk
Subject: Re: [matplotlib-devel] hist doesn't work with 2D arrays

Andrew Hawryluk wrote:

Hopefully this isn't old news for you. Since the 0.98 release, the histogram plot doesn't work properly with 2D arrays: it is quite slow and the output is wrong. Passing a flattened array produces the quick, correct output that we are accustomed to. Here is the test code I ran, and the attached image shows the output compared with the previous version.

import numpy as n
import matplotlib.pyplot as p

a = n.random.normal(size=10000)
a = a.reshape((100,100)) # make a 2D array of normally-distributed random numbers
p.hist(a)

Thanks for your work on matplotlib!

Hi Andrew,
2D arrays are now treated differently. An (N,M) 2D array is
interpreted as M data-sets with N elements each, e.g.

a = n.random.normal(size=10000)
a = a.reshape((1000,10))

is interpreted as 10 data-sets with 1000 elements each. See
histogram_demo_extended.py in examples/pylab_examples.

To reproduce the old behaviour you should use pylab.hist(a.flat).

Manuel

Andrew Hawryluk
<<hist-comparison.png>>

------------------------------------------------------------------------

------------------------------------------------------------------------

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08

------------------------------------------------------------------------

_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
matplotlib-devel List Signup and Options