matplotlib 1.1 "TypeError: a float is required" problem

Sankey Diagrams

I just updated matplotlib to 1.1 and want try the new features

and

Animation

but when I try the api example code: sankey_demo_basics.py

I got the error messages as below:

···

==============================================================================

Traceback (most recent call last):

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/figure.py”, line 884, in draw

func(*args)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/axes.py”, line 1983, in draw

a.draw(renderer)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/patches.py”, line 385, in draw

gc.set_linewidth(lw)

TypeError: a float is required

Traceback (most recent call last):

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/figure.py”, line 884, in draw

func(*args)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/axes.py”, line 1983, in draw

a.draw(renderer)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/patches.py”, line 385, in draw

gc.set_linewidth(lw)

TypeError: a float is required

==================================================================================

Then I looked into the file /Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/patches.py

at the line 384 the code is: gc.set_linewidth(lw)

I added “lw = np.float(lw)” before “gc.set_linewidth(lw)”, then the example code runs successfully.

Any help?

Thanks for any reply.


Mingkui Li

I suspect this bug is specific to the macosx backend. Can you
switch to another backend and confirm it doesn’t happen there? (I
can’t reproduce it on Linux).

Mike
···

http://p.sf.net/sfu/Citrix-VDIinaboxMatplotlib-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/matplotlib-users

Thank you, Mike.

I’ll try the Linux version to find out.

···

On Sat, Jan 7, 2012 at 12:06 AM, Michael Droettboom <mdroe@…86…> wrote:

I suspect this bug is specific to the macosx backend.  Can you

switch to another backend and confirm it doesn’t happen there? (I
can’t reproduce it on Linux).

Mike




On 01/06/2012 10:54 AM, Mingkui Li wrote:

Sankey Diagrams

I just updated matplotlib to 1.1 and want try the new features

and

Animation

but when I try the api
example code: sankey_demo_basics.py

I got the error messages as below:

==============================================================================

Traceback (most recent call last):

      File

“/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”,
line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

      File

“/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/figure.py”,
line 884, in draw

func(*args)

      File

“/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”,
line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

      File

“/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/axes.py”,
line 1983, in draw

a.draw(renderer)

      File

“/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”,
line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

      File

“/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/patches.py”,
line 385, in draw

gc.set_linewidth(lw)

TypeError: a float is required

Traceback (most recent call last):

      File

“/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”,
line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

      File

“/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/figure.py”,
line 884, in draw

func(*args)

      File

“/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”,
line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

      File

“/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/axes.py”,
line 1983, in draw

a.draw(renderer)

      File

“/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”,
line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

      File

“/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/patches.py”,
line 385, in draw

gc.set_linewidth(lw)

TypeError: a float is required

==================================================================================

Then I looked into the
file /Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/patches.py

at the line 384 the code is: gc.set_linewidth(lw)

    I added  "lw = np.float(lw)" before "gc.set_linewidth(lw)",

then the example code runs successfully.

Any help?

Thanks for any reply.

  Mingkui Li
------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! [http://p.sf.net/sfu/Citrix-VDIinabox](http://p.sf.net/sfu/Citrix-VDIinabox)
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
[https://lists.sourceforge.net/lists/listinfo/matplotlib-users](https://lists.sourceforge.net/lists/listinfo/matplotlib-users)

Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don’t need a complex

infrastructure or vast IT resources to deliver seamless, secure access to

virtual desktops. With this all-in-one solution, easily deploy virtual

desktops for less than the cost of PCs and save 60% on VDI infrastructure

costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Mingkui Li

The problem seems to originate from this line in lib/matplotlib/sankey.py:
patch = PathPatch(Path(vertices, codes),
fc=kwargs.pop(‘fc’, kwargs.pop(‘facecolor’,
#bfd1d4’)), # Custom defaults
lw=kwargs.pop(‘lw’,
kwargs.pop(‘linewidth’,
‘0.5’)),
**kwargs)
Note that the linewidth is set to the string ‘0.5’ rather than the float 0.5. gc.set_linewidth is then called with the string ‘0.5’ as the argument, which triggers the error. If I replace ‘0.5’ by 0.5, the example runs fine with the MacOSX backend.
Is there a reason why this needs to be a string here? I would think that in general gc.set_linewidth should only accept floats and ints.
-Michiel.

···

— On Fri, 1/6/12, Mingkui Li <ken.mk.li@…287…> wrote:

From: Mingkui Li <ken.mk.li@…287…>
Subject: [Matplotlib-users] matplotlib 1.1 “TypeError: a float is required” problem
To: matplotlib-users@lists.sourceforge.net
Date: Friday, January 6, 2012, 10:54 AM

Sankey Diagrams

I just updated matplotlib to 1.1 and want try the new features

and

Animation

but when I try the api example code: sankey_demo_basics.py

I got the error messages as below:

==============================================================================

Traceback (most recent call last):

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/figure.py”, line 884, in draw

func(*args)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/axes.py”, line 1983, in draw

a.draw(renderer)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/patches.py”, line 385, in draw

gc.set_linewidth(lw)

TypeError: a float is required

Traceback (most recent call last):

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/figure.py”, line 884, in draw

func(*args)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/axes.py”, line 1983, in draw

a.draw(renderer)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/patches.py”, line 385, in draw

gc.set_linewidth(lw)

TypeError: a float is required

==================================================================================

Then I looked into the file /Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/patches.py

at the line 384 the code is: gc.set_linewidth(lw)

I added “lw = np.float(lw)” before “gc.set_linewidth(lw)”, then the example code runs successfully.

Any help?

Thanks for any reply.


Mingkui Li

-----Inline Attachment Follows-----


Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don’t need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual
desktops for less than the cost of PCs and save 60% on VDI infrastructure
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox

-----Inline Attachment Follows-----


Matplotlib-users mailing list
Matplotlib-users@…431…ists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Yes, I think this is the origin of the Error.

Thank you all!

BTW, why the email title of all other people posts begin with ‘[matplotlib-user]’? does this should be added by hand every time when I post a topic?

···

On Sat, Jan 7, 2012 at 11:44 AM, Michiel de Hoon <mjldehoon@…120…9…> wrote:

The problem seems to originate from this line in lib/matplotlib/sankey.py:
patch = PathPatch(Path(vertices, codes),
fc=kwargs.pop(‘fc’, kwargs.pop(‘facecolor’,
#bfd1d4’)), # Custom defaults
lw=kwargs.pop(‘lw’,
kwargs.pop(‘linewidth’,
‘0.5’)),
**kwargs)
Note that the linewidth is set to the string ‘0.5’ rather than the float 0.5. gc.set_linewidth is then called with the string ‘0.5’ as the argument, which triggers the error. If I replace ‘0.5’ by 0.5, the example runs fine with the MacOSX backend.
Is there a reason why this needs to be a string here? I would think that in general gc.set_linewidth should only accept floats and ints.
-Michiel.
— On Fri, 1/6/12, Mingkui Li <ken.mk.li@…287…> wrote:

From: Mingkui Li <ken.mk.li@…287…>
Subject: [Matplotlib-users] matplotlib 1.1 “TypeError: a float is required” problem

To: matplotlib-users@lists.sourceforge.net
Date: Friday, January 6, 2012, 10:54 AM

Sankey Diagrams

I just updated matplotlib to 1.1 and want try the new features

and

Animation

but when I try the api example code: sankey_demo_basics.py

I got the error messages as below:

==============================================================================

Traceback (most recent call last):

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/figure.py”, line 884, in draw

func(*args)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/axes.py”, line 1983, in draw

a.draw(renderer)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/patches.py”, line 385, in draw

gc.set_linewidth(lw)

TypeError: a float is required

Traceback (most recent call last):

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/figure.py”, line 884, in draw

func(*args)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/axes.py”, line 1983, in draw

a.draw(renderer)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/artist.py”, line 55, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File “/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/patches.py”, line 385, in draw

gc.set_linewidth(lw)

TypeError: a float is required

==================================================================================

Then I looked into the file /Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/matplotlib/patches.py

at the line 384 the code is: gc.set_linewidth(lw)

I added “lw = np.float(lw)” before “gc.set_linewidth(lw)”, then the example code runs successfully.

Any help?

Thanks for any reply.


Mingkui Li

-----Inline Attachment Follows-----


Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don’t need a complex

infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual
desktops for less than the cost of PCs and save 60% on VDI infrastructure

costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox

-----Inline Attachment Follows-----


Matplotlib-users mailing list
Matplotlib-users@…1838…urceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Mingkui Li

No, don’t do that. The added part of the title is done automatically by the list server. However, on this list, we post replies on the bottom.

Ben Root

···

On Saturday, January 7, 2012, Mingkui Li <ken.mk.li@…287…> wrote:

Yes, I think this is the origin of the Error.
Thank you all!
BTW, why the email title of all other people posts begin with ‘[matplotlib-user]’? does this should be added by hand every time when I post a topic?