473,805 Members | 2,111 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.arra y(a, typecode, copy=0, savespace=saves pace)
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+widt h/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 5843
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.arra y(a, typecode, copy=0, savespace=saves pace)
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+widt h/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.arra y(a, typecode, copy=0, savespace=saves pace)
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**********@g mx.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.arra y(a, typecode, copy=0, savespace=saves pace)
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**********@g mx.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.arra y(a, typecode, copy=0, savespace=saves pace)
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**********@g mx.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
4990
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 python-2.3 with matplotlib-0.32. I'm a total newbie with matplotlib (I installed it yesterday), so what am I doing wrong? An example code below: ------------------------------------------ #!/usr/bin/env python2.3
0
1576
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 for NumPy 0.9.5 and Matplotlib 0.87.1, I get this error message: >>> import pylab as p Traceback (most recent call last): File "<pyshell#4>", line 1, in ? import pylab as p File "C:\Python24\Lib\site-packages\pylab.py", line 1, in ?
2
4858
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 containing the frozen executable and other libs to a new machine, I get the following error: Traceback (most recent call last): File "/home/fccoelho/Downloads/cx_Freeze-3.0.2/initscripts/Console.py",
2
11658
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. http://matplotlib.sourceforge.net/matplotlib.pylab.html#-contour appears to be a good reference if you already know how to use contour(), but I could glean zero clues from it on how to actually use contour(). For example, it doesn't explain what the actual formats/types of the parameters. It...
4
3356
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 on the matplotlib mailing list, but I have a hard enough time browsing sourceforge's achives (frequent internal server errors). Here is some output:
3
4729
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 on other comps... i used py2exe... i wrote a setup.py whose contents are : from distutils.core import setup import py2exe import matplotlib setup(console=, options={ 'py2exe': { 'packages' : ,
2
3534
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: In member function 'Py::Object Glyph::get_path(FT_FaceRec_* const&)': src/ft2font.cpp:441: error: 'FT_CURVE_TAG_CUBIC' was not declared in this scope
4
9695
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 I attempt to run the exe created. In searching the web, it appears this is an issue when others tried to use py2exe as well. Unfortunately, the few hits I saw doesn't include enough details to inspire me as to what I should be doing in my
2
3110
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 freetype as required by matplotlib, and the installation all went well. But when I try to plot even the simplest stuff, ex: plot()
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10614
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10369
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10109
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7649
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5544
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3847
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.