Multi-histogram example generates errors

I’m trying to make a bar-style histogram, along the lines of the last example figure from the extended histogram demo:

http://matplotlib.sourceforge.net/examples/pylab_examples/histogram_demo_extended.html

in which the several arrays to be histogrammed do not have the same length. However, I’m getting an error about “setting an array element with a sequence”, even when I just cut-and-paste in the example code. The previous multi-histogram examples in which the array being plotted is generated using: x = mu + sigma*randn(1000,3) work fine though.

Am I doing something stupid?

Here’s the trace:

In [25]: n, bins, patches = hist( [x0,x1,x2], 10, histtype=‘bar’)

···

ValueError Traceback (most recent call last)

/Users/zane/svn/googlecode/ in ()

/Library/Python/2.5/site-packages/matplotlib-0.98.3-py2.5-macosx-10.3-i386.egg/matplotlib/pyplot.pyc in hist(*args, **kwargs)

1866 hold(h)

1867 try:

-> 1868 ret = gca().hist(*args, **kwargs)

1869 draw_if_interactive()

1870 except:

/Library/Python/2.5/site-packages/matplotlib-0.98.3-py2.5-macosx-10.3-i386.egg/matplotlib/axes.pyc in hist(self, x, bins, range, normed, cumulative, bottom, histtype, align, orientation, rwidth, log, **kwargs)

6211

6212 # todo: make hist() work with list of arrays with different lengths

-> 6213 x = np.asarray(x).copy()

6214 if len(x.shape)==2 and min(x.shape)==1:

6215 x.shape = max(x.shape),

/Library/Python/2.5/site-packages/numpy-1.2.0.dev5677-py2.5-macosx-10.3-i386.egg/numpy/core/numeric.pyc in asarray(a, dtype, order)

228

229 “”"

–> 230 return array(a, dtype, copy=False, order=order)

231

232 def asanyarray(a, dtype=None, order=None):

ValueError: setting an array element with a sequence.

Zane Selvans

Amateur Earthling

zane@…1923…

303/815-6866

http://zaneselvans.org

PGP Key: 55E0815F

Zane Selvans wrote:

I'm trying to make a bar-style histogram, along the lines of the last example figure from the extended histogram demo:

http://matplotlib.sourceforge.net/examples/pylab_examples/histogram_demo_extended.html

in which the several arrays to be histogrammed do not have the same length. However, I'm getting an error about "setting an array element with a sequence", even when I just cut-and-paste in the example code. The previous multi-histogram examples in which the array being plotted is generated using: x = mu + sigma*randn(1000,3) work fine though.

Am I doing something stupid?

No.

The example code runs with mpl from svn, so I suspect you are running into an example that was written to show capabilities added since the last release. In fact, it looks like that 6212 #todo is the clue: it is not found in the svn version.

Eric

···

Here's the trace:

In [25]: n, bins, patches = hist( [x0,x1,x2], 10, histtype='bar')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)

/Users/zane/svn/googlecode/<ipython console> in <module>()

/Library/Python/2.5/site-packages/matplotlib-0.98.3-py2.5-macosx-10.3-i386.egg/matplotlib/pyplot.pyc in hist(*args, **kwargs)
   1866 hold(h)
   1867 try:
-> 1868 ret = gca().hist(*args, **kwargs)
   1869 draw_if_interactive()
   1870 except:

/Library/Python/2.5/site-packages/matplotlib-0.98.3-py2.5-macosx-10.3-i386.egg/matplotlib/axes.pyc in hist(self, x, bins, range, normed, cumulative, bottom, histtype, align, orientation, rwidth, log, **kwargs)
   6211 6212 # todo: make hist() work with list of arrays with different lengths
-> 6213 x = np.asarray(x).copy()
   6214 if len(x.shape)==2 and min(x.shape)==1:
   6215 x.shape = max(x.shape),

/Library/Python/2.5/site-packages/numpy-1.2.0.dev5677-py2.5-macosx-10.3-i386.egg/numpy/core/numeric.pyc in asarray(a, dtype, order)
    228 229 """
--> 230 return array(a, dtype, copy=False, order=order)
    231 232 def asanyarray(a, dtype=None, order=None):

ValueError: setting an array element with a sequence.


Zane Selvans
Amateur Earthling
zane@…1923… <mailto:zane@…1923…>
303/815-6866
http://zaneselvans.org
PGP Key: 55E0815F

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

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

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

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Hmm. It seems like it might be better to have the default online documentation generated from the current release, instead of the bleeding edge. The title of the page does after all say: “Matplotlib v0.98.3 documentation”. Of course there could be an svn version accessible somewhere too, but having this kind of disconnect between what people have installed, and what the default doc refers to, will probably create other headaches too.

Just my $0.02,

Zane

···

On Nov 12, 2008, at 8:12 PM, Eric Firing wrote:

The example code runs with mpl from svn, so I suspect you are running into an example that was written to show capabilities added since the last release. In fact, it looks like that 6212 #todo is the clue: it is not found in the svn version.

Zane Selvans

Amateur Earthling

zane@…1923…

303/815-6866

http://zaneselvans.org

PGP Key: 55E0815F

Zane Selvans wrote:

The example code runs with mpl from svn, so I suspect you are running into an example that was written to show capabilities added since the last release. In fact, it looks like that 6212 #todo is the clue: it is not found in the svn version.

Hmm. It seems like it might be better to have the default online documentation generated from the current release, instead of the bleeding edge. The title of the page does after all say: "Matplotlib v0.98.3 documentation". Of course there could be an svn version accessible somewhere too, but having this kind of disconnect between what people have installed, and what the default doc refers to, will probably create other headaches too.

I agree. I don't know anything about how the web site is generated, though, so I don't know how easy or hard this is. We just switched to a new documentation generation system. Maybe the scheme you suggest, with docs matching versions (at least the latest release and svn; possibly even keeping access to older versions as new versions are released, the way Python.org does it) can be implemented with the next release.

I wonder if any users or developers might be interested in becoming developers specializing in the website and documentation, to take some of the load off of John and Mike...

Eric

···

On Nov 12, 2008, at 8:12 PM, Eric Firing wrote:

Just my $0.02,
Zane


Zane Selvans
Amateur Earthling
zane@…1923… <mailto:zane@…1923…>
303/815-6866
http://zaneselvans.org
PGP Key: 55E0815F