matplotlib: TypeError: a float is required
John Machin
sjmachin at lexicon.net
Sun Sep 17 09:15:50 EDT 2006
Andi Clemens wrote:
> Hi,
>
> everytime I try to plot a bar with matplotlib I get the following error
> message:
> Traceback (most recent call last):
> File "bar_stacked.py", line 13, in ?
> p1 = bar(ind, menMeans, width, color='r', yerr=womenStd)
> File "/usr/lib/python2.4/site-packages/matplotlib/pylab.py", line
> 1641, in bar
> ret = gca().bar(*args, **kwargs)
> File "/usr/lib/python2.4/site-packages/matplotlib/axes.py", line
> 2485, in bar
> xerr = asarray([xerr]*nbars, Float)
> File "/usr/lib/python2.4/site-packages/Numeric/Numeric.py", line 134,
> in asarray
> return multiarray.array(a, typecode, copy=0, savespace=savespace)
> TypeError: a float is required
>
>
> So I guess it has something to do with Numeric.py, but I can't figure
> out what the problem is. I tried to google but found nothing...
>
> Anyone has the same problem? I can plot all kinds of graphics with
> matplotlib, but the only type I'm interested in (bars) will not work.
>
> I tried the examples coming with matplotlib, but even those don't work.
>
> Here is the example code which produces the above error:
> #!/usr/bin/env python
> # a stacked bar plot with errorbars
> from pylab import *
>
> N = 5
> menMeans = (20, 35, 30, 35, 27)
> womenMeans = (25, 32, 34, 20, 25)
> menStd = (2, 3, 4, 1, 2)
> womenStd = (3, 5, 2, 3, 3)
> ind = arange(N) # the x locations for the groups
> width = 0.35 # the width of the bars: can also be len(x) sequence
>
> p1 = bar(ind, menMeans, width, color='r', yerr=womenStd)
Call me crazy -- I know SFA about matplotlib -- but I'd expect anything
scientific to barf if given tuples of integers to play with, and
following the docs links matplotlib > pylab > bar we find:
"""
bar(*args, **kwargs)
BAR(left, height, width=0.8, bottom=0,
color='b', yerr=None, xerr=None, ecolor='k', capsize=3)
Make a bar plot with rectangles at
left, left+width, 0, height
left and height are Numeric arrays.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
"""
Which of us is missing what?
Cheers,
John
More information about the Python-list
mailing list