473,503 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

matplotlib: TypeError: a float is required

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)
p2 = bar(ind, womenMeans, width, color='y',
bottom=menMeans, yerr=menStd)

ylabel('Scores')
title('Scores by group and gender')
xticks(ind+width/2., ('G1', 'G2', 'G3', 'G4', 'G5') )
yticks(arange(0,81,10))
legend( (p1[0], p2[0]), ('Men', 'Women') )

show()
Anyone has matplotlib installed and gets the same error?
I need to create some charts for a project I do at work, so maybe there
are other modules out there creating charts??

Andi

--
homepage: http://www.the-grudge.net
ICQ: 9450091
Skype: thegrudge_2
Mozilla Thunderbird 1.5.0.5
Arch Linux
Sep 17 '06 #1
8 5827
btw, these are the versions I'm using (Archlinux):

Python: 2.4.3 (python-2.4.3-3)
matplotlib: 0.87.4 (python-matplotlib-0.87.4-1)
PyGTK: 2.8.6 (pygtk-2.8.6-3)

Andi
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)
p2 = bar(ind, womenMeans, width, color='y',
bottom=menMeans, yerr=menStd)

ylabel('Scores')
title('Scores by group and gender')
xticks(ind+width/2., ('G1', 'G2', 'G3', 'G4', 'G5') )
yticks(arange(0,81,10))
legend( (p1[0], p2[0]), ('Men', 'Women') )

show()
Anyone has matplotlib installed and gets the same error?
I need to create some charts for a project I do at work, so maybe there
are other modules out there creating charts??

Andi
--
homepage: http://www.the-grudge.net
ICQ: 9450091
Skype: thegrudge_2
Mozilla Thunderbird 1.5.0.5
Arch Linux
Sep 17 '06 #2

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

Sep 17 '06 #3
Sorry but english isn't my native language so I don't really get what
you are trying to tell me, it took me quite a long time to figure out
what SFA means (I guess it is Sweet Fanny Adams =nothing at all).

All examples were taken from the matplotlib-homepage but they won't work
on my installation and I don't know why.
You point out that "left and height are Numeric arrays", and that is
exactly what they are, so what am I missing?

I tried nearly 10 examples from different websites and tutorials and
none of them worked!
So I don't think I'm doing something wrong, or am I?

Andi

John Machin wrote:
>
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
--
homepage: http://www.the-grudge.net
ICQ: 9450091
Skype: thegrudge_2
Mozilla Thunderbird 1.5.0.5
Arch Linux
Sep 17 '06 #4
Andi Clemens <an**********@gmx.netwrites:
>
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.
It looks like it doesn't like not having xerr set. The documentation
says

xerr and yerr, if not None, will be used to generate errorbars on
the bar chart

implying that if they are None (the default), then no errorbars will
be generated. But that doesn't seem to be the case. When I add an xerr
to both p1 and p2

p1 = bar(ind, menMeans, width, color='r', yerr=womenStd,
xerr=zeros(N))
p2 = bar(ind, womenMeans, width, color='y',
bottom=menMeans, yerr=menStd, xerr=zeros(N))

I get the following bar chart

http://img176.imageshack.us/my.php?image=imagenx6.png

with no errors.

Tim
Sep 17 '06 #5
THATS IT! Thanks!
But why are all the examples wrong? Maybe they changed the API?

Andi

Tim Heaney wrote:
Andi Clemens <an**********@gmx.netwrites:
>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.

It looks like it doesn't like not having xerr set. The documentation
says

xerr and yerr, if not None, will be used to generate errorbars on
the bar chart

implying that if they are None (the default), then no errorbars will
be generated. But that doesn't seem to be the case. When I add an xerr
to both p1 and p2

p1 = bar(ind, menMeans, width, color='r', yerr=womenStd,
xerr=zeros(N))
p2 = bar(ind, womenMeans, width, color='y',
bottom=menMeans, yerr=menStd, xerr=zeros(N))

I get the following bar chart

http://img176.imageshack.us/my.php?image=imagenx6.png

with no errors.

Tim
--
homepage: http://www.the-grudge.net
ICQ: 9450091
Skype: thegrudge_2
Mozilla Thunderbird 1.5.0.5
Arch Linux
Sep 17 '06 #6

Andi Clemens wrote:
>
All examples were taken from the matplotlib-homepage but they won't work
on my installation and I don't know why.
You point out that "left and height are Numeric arrays", and that is
exactly what they are, so what am I missing?
Looks to me like for "height" you are passing in menMeans which is a
tuple containing integers. The standard deviation args have the same
problem
>
I tried nearly 10 examples from different websites and tutorials and
none of them worked!
Care to point me at the smallest other example that didn't work? Did
you copy/paste the example or did you retype it? Does "not work" mean
each gave the same error from the same line of code in Numeric? If not,
is there any pattern that you can detect?

Sep 17 '06 #7
Tim Heaney found out what the problem is, thanks for your help!
;-)

Andi

John Machin wrote:
Andi Clemens wrote:
>All examples were taken from the matplotlib-homepage but they won't work
on my installation and I don't know why.
You point out that "left and height are Numeric arrays", and that is
exactly what they are, so what am I missing?

Looks to me like for "height" you are passing in menMeans which is a
tuple containing integers. The standard deviation args have the same
problem
>I tried nearly 10 examples from different websites and tutorials and
none of them worked!

Care to point me at the smallest other example that didn't work? Did
you copy/paste the example or did you retype it? Does "not work" mean
each gave the same error from the same line of code in Numeric? If not,
is there any pattern that you can detect?
--
homepage: http://www.the-grudge.net
ICQ: 9450091
Skype: thegrudge_2
Mozilla Thunderbird 1.5.0.5
Arch Linux
Sep 17 '06 #8
Andi Clemens <an**********@gmx.netwrites:
>
THATS IT! Thanks!
But why are all the examples wrong? Maybe they changed the API?
I think it's a bug. You should report it. Looking at

http://matplotlib.sourceforge.net/faq.html#BUGREPORT

it seems you can use either the mailing list or sourceforge.

Tim
Sep 17 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4974
by: Pekko Piirola | last post by:
I'm trying to make an animation with matplotlib. The problem: whenever I try to rescale or move the plot with the buttons of plotting window, the animation stops. My system is Debian Woody and...
0
1563
by: sturlamolden | last post by:
Recently, I have been trying to test Python as an alternative to Matlab. I have problems getting matplotlib to work on Windows (ActivePython 2.4.2). After installing the precompiled binary packages...
2
4829
by: Flavio | last post by:
I am trying to freeze an application which imports matplotlib. It all works fine on the machine where it was frozen. The executable runs without a glitch. But when I move the directory...
2
11635
by: Grant Edwards | last post by:
I downloaded examples/contour_demo.py, and it doesn't run. I've searched both the user guide and the Wiki for "contour" and got zero hits. ...
4
3323
by: Bill Jackson | last post by:
Hi, I'm having some trouble plotting with the following matplotlibrc: text.usetex : True I tried clearing the cache files under ~/.matplotlib, but this did not help the problem. I'd post...
3
4699
by: vajratkarviraj | last post by:
i hav python2.5, matplotlib0.90.1, and py2exe for python 2.5 all on windows xp... i hav a python program(letsc.py) which uses the matplotlib package... and i want 2 make an exe of it for distribution...
2
3516
by: John | last post by:
I'm trying to install matplotlib and currently getting the below error. I searched the group and google and couldn't find anything similar... Any ideas? Thanks in advance! src/ft2font.cpp:...
4
9648
by: John Henry | last post by:
Has anybody been able to create an exe of their python applications involving matplotlib using pyinstall (ver 1.3)? I am getting a: RuntimeError: Could not find the matplotlib data files when...
2
3090
by: Magdoll | last post by:
Has anyone run into the same problem I have? I used to run matplotlib with Python2.5 and everything worked fine. Now I use Python2.6, and everything falls apart. I installed numpy, libpng, and...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7451
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4667
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.