EMF output: too many values to unpack error

I use matplotlib through IPython on Windows XP with Python 2.6.6 and Qt4Agg
as backend

Trying to save plot as EMF, after installing pyemf 2.0 raises this
error:

too many values to unpack

Trying to save plot as EMF, after installing pyemf 2.0 raises this
error:

too many values to unpack

Some code sample would help. It means what it says - trying to assign
tuples or whatever to too few values, e.g.:
x,y= (1,2,3)

Is the error raised in your code or a library?

···

---
Nick

Some code sample would help. It means what it says - trying to assign
tuples or whatever to too few values, e.g.:
x,y= (1,2,3)

Is the error raised in your code or a library?

···

On 9 June 2011 15:13, Klonuo Umom <klonuo@...287...> wrote:

Trying to save plot as EMF, after installing pyemf 2.0 raises this
error:

too many values to unpack

---
Nick

Take any for example, like 'plot([1,2,3])' it doesn't matter

I described my environment: I use matplotlib through IPython on Windows
XP with Python 2.6.6 and Qt4Agg as backend

Qt backend shows the plot, then I press save icon and choose EMF. Next,
Qt pops dialog saying 'too many values to unpack'.
Same happens also with WXAgg. Seems like it's something broken between
matplotlib and pyemf, but I don't see how I can trace this

Saving PNG, EPS works fine as expected

···

On 09.06.2011 18:06:57 Nick Veitch wrote:

Some code sample would help. It means what it says - trying to assign
tuples or whatever to too few values, e.g.:
x,y= (1,2,3)

Is the error raised in your code or a library?

Question, does the following cause the same error?

from pylab import *
plot([1, 2, 3])
savefig(‘foobar.emf’)

There might be an important difference between saving from the save dialog and saving directly through the savefig command.

Ben Root

···

On Thu, Jun 9, 2011 at 11:19 AM, Klonuo Umom <klonuo@…287…> wrote:

On 09.06.2011 18:06:57 Nick Veitch wrote:

Some code sample would help. It means what it says - trying to assign

tuples or whatever to too few values, e.g.:

x,y= (1,2,3)

Is the error raised in your code or a library?

Take any for example, like ‘plot([1,2,3])’ it doesn’t matter

I described my environment: I use matplotlib through IPython on Windows
XP with Python 2.6.6 and Qt4Agg as backend

Qt backend shows the plot, then I press save icon and choose EMF. Next,

Qt pops dialog saying ‘too many values to unpack’.

Same happens also with WXAgg. Seems like it’s something broken between

matplotlib and pyemf, but I don’t see how I can trace this

Saving PNG, EPS works fine as expected

Good idea. Here is trace (I called your snippet mpl.py):

Traceback (most recent call last):
  File "C:\Python26\Scripts\mpl.py", line 3, in <module>
    savefig('foobar.emf')
  File "C:\Python26\lib\site-packages\matplotlib\pyplot.py", line 363, in savefig
    return fig.savefig(*args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\figure.py", line 1084, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\backends\backend_wxagg.py", line 100, in print_figure
    FigureCanvasAgg.print_figure(self, filename, *args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\backend_bases.py", line 1923, in print_figure
    **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\backend_bases.py", line 1723, in print_emf
    return emf.print_emf(*args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\backends\backend_emf.py", line 717, in print_emf
    self.figure.draw(renderer)
  File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\figure.py", line 738, in draw
    if self.frameon: self.patch.draw(renderer)
  File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\patches.py", line 411, in draw
    renderer.draw_path(gc, tpath, affine, rgbFace)
  File "C:\Python26\lib\site-packages\matplotlib\backends\backend_emf.py", line 258, in draw_path
    self.select_brush(rgbFace)
  File "C:\Python26\lib\site-packages\matplotlib\backends\backend_emf.py", line 565, in select_brush
    brush=EMFBrush(self.emf,rgb)
  File "C:\Python26\lib\site-packages\matplotlib\backends\backend_emf.py", line 105, in __init__
    r,g,b=rgb
ValueError: too many values to unpack

···

On 09.06.2011 18:47:42 Benjamin Root wrote:

Question, does the following cause the same error?

from pylab import *
plot([1, 2, 3])
savefig('foobar.emf')

There might be an important difference between saving from the save dialog
and saving directly through the savefig command.

Ah, so the bug is in the emf backend. Which version of matplotlib are you using?

import matplotlib
print matplotlib.version

Ben Root

···

On Thu, Jun 9, 2011 at 11:56 AM, Klonuo Umom <klonuo@…1003…7…> wrote:

On 09.06.2011 18:47:42 Benjamin Root wrote:

Question, does the following cause the same error?

from pylab import *

plot([1, 2, 3])

savefig(‘foobar.emf’)

There might be an important difference between saving from the save dialog

and saving directly through the savefig command.

Good idea. Here is trace (I called your snippet mpl.py):

Traceback (most recent call last):

File “C:\Python26\Scripts\mpl.py”, line 3, in

savefig('foobar.emf')

File “C:\Python26\lib\site-packages\matplotlib\pyplot.py”, line 363, in savefig

return fig.savefig(*args, **kwargs)

File “C:\Python26\lib\site-packages\matplotlib\figure.py”, line 1084, in savefig

self.canvas.print_figure(*args, **kwargs)

File “C:\Python26\lib\site-packages\matplotlib\backends\backend_wxagg.py”, line 100, in print_figure

FigureCanvasAgg.print_figure(self, filename, *args, **kwargs)

File “C:\Python26\lib\site-packages\matplotlib\backend_bases.py”, line 1923, in print_figure

**kwargs)

File “C:\Python26\lib\site-packages\matplotlib\backend_bases.py”, line 1723, in print_emf

return emf.print_emf(*args, **kwargs)

File “C:\Python26\lib\site-packages\matplotlib\backends\backend_emf.py”, line 717, in print_emf

self.figure.draw(renderer)

File “C:\Python26\lib\site-packages\matplotlib\artist.py”, line 55, in draw_wrapper

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

File “C:\Python26\lib\site-packages\matplotlib\figure.py”, line 738, in draw

if self.frameon: self.patch.draw(renderer)

File “C:\Python26\lib\site-packages\matplotlib\artist.py”, line 55, in draw_wrapper

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

File “C:\Python26\lib\site-packages\matplotlib\patches.py”, line 411, in draw

renderer.draw_path(gc, tpath, affine, rgbFace)

File “C:\Python26\lib\site-packages\matplotlib\backends\backend_emf.py”, line 258, in draw_path

self.select_brush(rgbFace)

File “C:\Python26\lib\site-packages\matplotlib\backends\backend_emf.py”, line 565, in select_brush

brush=EMFBrush(self.emf,rgb)

File “C:\Python26\lib\site-packages\matplotlib\backends\backend_emf.py”, line 105, in init

r,g,b=rgb

ValueError: too many values to unpack

Latest stable I guess: 1.0.1

···

On 09.06.2011 19:00:34 Benjamin Root wrote:

Ah, so the bug is in the emf backend. Which version of matplotlib are you
using?

import matplotlib
print matplotlib.__version__

I looks like backend_emf.py is choking on rgba values. Is EMF unable to handle Alpha channels? The fix should be fairly easy, though.

Ben Root

···

On Thu, Jun 9, 2011 at 12:02 PM, Klonuo Umom <klonuo@…1003…7…> wrote:

On 09.06.2011 19:00:34 Benjamin Root wrote:

Ah, so the bug is in the emf backend. Which version of matplotlib are you

using?

import matplotlib

print matplotlib.version

Latest stable I guess: 1.0.1

I have no idea. I installed pyemf today as mpl asked me to if I want to
export to EMF.

I wanted to use EMF as it's most convenient to use in Word. Hassle free
vector format that MS likes. It's not problem for me to convert PS/EPS
to EMF, thou problem should be known

···

On 09.06.2011 19:29:35 Benjamin Root wrote:

I looks like backend_emf.py is choking on rgba values. Is EMF unable to
handle Alpha channels? The fix should be fairly easy, though.

I set up pull requests to fix this problem, so the v1.0.x-maint branch and the master branch should soon have the fixes commited to them. You can get the latest bugfixed branch for v1.0.1 at https://github.com/matplotlib/matplotlib/tree/v1.0.x-maint, although that would mean having to build from source. You could also just edit your copy of the file C:\Python26\lib\site-
packages\matplotlib\backends\backend_emf.py so that [:3] is added to the end of lines 69 and 105. This page should show you what changes you need: https://github.com/WeatherGod/matplotlib/commit/bf8d9d6f7cea1546c736d3897387698e6ae5e5b3

I hope that helps!

Ben Root

···

On Thu, Jun 9, 2011 at 12:40 PM, Klonuo Umom <klonuo@…1003…7…> wrote:

On 09.06.2011 19:29:35 Benjamin Root wrote:

I looks like backend_emf.py is choking on rgba values. Is EMF unable to

handle Alpha channels? The fix should be fairly easy, though.

I have no idea. I installed pyemf today as mpl asked me to if I want to

export to EMF.

I wanted to use EMF as it’s most convenient to use in Word. Hassle free

vector format that MS likes. It’s not problem for me to convert PS/EPS

to EMF, thou problem should be known

Thanks. It outputs fine now :slight_smile:

Cheers

···

On 09.06.2011 19:52:18 Benjamin Root wrote:

You could also just edit your copy
of the file C:\Python26\lib\site-
packages\matplotlib\backends\backend_emf.py so that [:3] is added to the end
of lines 69 and 105. This page should show you what changes you need:
Fix unpacking of rgb values to explicitly extract the first 3 values … · WeatherGod/matplotlib@bf8d9d6 · GitHub

I hope that helps!

Benjamin Root-2 wrote

I set up pull requests to fix this problem, so the v1.0.x-maint branch and
the master branch should soon have the fixes commited to them. You can
get
the latest bugfixed branch for v1.0.1 at
https://github.com/matplotlib/matplotlib/tree/v1.0.x-maint, although that
would mean having to build from source. You could also just edit your
copy
of the file C:\Python26\lib\site-
packages\matplotlib\backends\backend_emf.py so that [:3] is added to the
end
of lines 69 and 105. This page should show you what changes you need:
Fix unpacking of rgb values to explicitly extract the first 3 values … · WeatherGod/matplotlib@bf8d9d6 · GitHub

I hope that helps!

Ben Root

Hi,

I am having the same problem when trying to save a figure to a .emf file via
pylab.savefig().
I have tried updating backend_emf.py as suggested but this does not fix the
problem, it still has a problem with the updated code(see below).
The only difference I can see with the original poster is that I am using
backend_qt4agg.py rather than backend_wxagg.py in the original posters code.
This shouldn't change the fix, should it ?

pylab.savefig('nrg.emf')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python26\lib\site-packages\matplotlib\pyplot.py", line 363, in
savefig
    return fig.savefig(*args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\figure.py", line 1084, in
savefig
    self.canvas.print_figure(*args, **kwargs)
  File
"C:\Python26\lib\site-packages\matplotlib\backends\backend_qt4agg.py", line
144, in print_figure
    FigureCanvasAgg.print_figure(self, *args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\backend_bases.py", line
1923, in print_figure
    **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\backend_bases.py", line
1723, in print_emf
    return emf.print_emf(*args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\backends\backend_emf.py",
line 717, in print_emf
    self.figure.draw(renderer)
  File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 55, in
draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\figure.py", line 738, in
draw
    if self.frameon: self.patch.draw(renderer)
  File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 55, in
draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\patches.py", line 411, in
draw
    renderer.draw_path(gc, tpath, affine, rgbFace)
  File "C:\Python26\lib\site-packages\matplotlib\backends\backend_emf.py",
line 258, in draw_path
    self.select_brush(rgbFace)
  File "C:\Python26\lib\site-packages\matplotlib\backends\backend_emf.py",
line 565, in select_brush
    brush=EMFBrush(self.emf,rgb)
  File "C:\Python26\lib\site-packages\matplotlib\backends\backend_emf.py",
line 105, in __init__
    r,g,b=rgb[:3]
ValueError: too many values to unpack

···

On Thu, Jun 9, 2011 at 12:40 PM, Klonuo Umom &lt; > klonuo@ > &gt; wrote:

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/EMF-output-too-many-values-to-unpack-error-tp11466p39267.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Does it fail for the example I originally gave?

from pylab import *
plot([1, 2, 3])
savefig(“foobar.emf”)

Ben Root

···

On Fri, Oct 5, 2012 at 6:38 AM, Usjes <oisin_nz@…225…> wrote:

Benjamin Root-2 wrote

On Thu, Jun 9, 2011 at 12:40 PM, Klonuo Umom <

klonuo@

wrote:

I set up pull requests to fix this problem, so the v1.0.x-maint branch and

the master branch should soon have the fixes commited to them. You can

get

the latest bugfixed branch for v1.0.1 at

https://github.com/matplotlib/matplotlib/tree/v1.0.x-maint, although that

would mean having to build from source. You could also just edit your

copy

of the file C:\Python26\lib\site-

packages\matplotlib\backends\backend_emf.py so that [:3] is added to the

end

of lines 69 and 105. This page should show you what changes you need:

https://github.com/WeatherGod/matplotlib/commit/bf8d9d6f7cea1546c736d3897387698e6ae5e5b3

I hope that helps!

Ben Root

Hi,

I am having the same problem when trying to save a figure to a .emf file via

pylab.savefig().

I have tried updating backend_emf.py as suggested but this does not fix the

problem, it still has a problem with the updated code(see below).

The only difference I can see with the original poster is that I am using

backend_qt4agg.py rather than backend_wxagg.py in the original posters code.

This shouldn’t change the fix, should it ?

Benjamin Root-2 wrote

Does it fail for the example I originally gave?

from pylab import *
plot([1, 2, 3])
savefig("foobar.emf")

Ben Root

Yes, it fails even with the simple plot suggested; see log below. I am new
to Python but I did also try inserting the command:
print rgb
preceding the offending line, to get an idea of what the dimensions of 'rgb'
are but the print statement also fails due to 'too many values to unpack'

savefig("foobar.emf")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python26\lib\site-packages\matplotlib\pyplot.py", line 363, in
savefig
    return fig.savefig(*args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\figure.py", line 1084, in
savefig
    self.canvas.print_figure(*args, **kwargs)
  File
"C:\Python26\lib\site-packages\matplotlib\backends\backend_qt4agg.py", line
144, in print_figure
    FigureCanvasAgg.print_figure(self, *args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\backend_bases.py", line
1923, in print_figure
    **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\backend_bases.py", line
1723, in print_emf
    return emf.print_emf(*args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\backends\backend_emf.py",
line 717, in print_emf
    self.figure.draw(renderer)
  File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 55, in
draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\figure.py", line 738, in
draw
    if self.frameon: self.patch.draw(renderer)
  File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 55, in
draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\patches.py", line 411, in
draw
    renderer.draw_path(gc, tpath, affine, rgbFace)
  File "C:\Python26\lib\site-packages\matplotlib\backends\backend_emf.py",
line 258, in draw_path
    self.select_brush(rgbFace)
  File "C:\Python26\lib\site-packages\matplotlib\backends\backend_emf.py",
line 565, in select_brush
    brush=EMFBrush(self.emf,rgb)
  File "C:\Python26\lib\site-packages\matplotlib\backends\backend_emf.py",
line 105, in __init__
    r,g,b=rgb[:3]
ValueError: too many values to unpack

···

On Fri, Oct 5, 2012 at 6:38 AM, Usjes &lt; > oisin_nz@...4225... > &gt; wrote:

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/EMF-output-too-many-values-to-unpack-error-tp11466p39275.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Actually, that is very telling… Did you restart python after editing the .py file? Python will only load a source file once in a session (unless explicitly forced to do a reload, but that is not intended for newbies). So, any changes to any source .py file will not take effect until you restart your python session. This is different from other languages like Matlab.

Ben Root

P.S. - The way I am able to deduce this is that when an exception occurs, the “compiled” code will tell python which lines it came from in the original source file so that python can display the traceback. If you edit the source file to add a line before the line that triggers a traceback, it can look like the wrong line is triggering the error because the compiled code doesn’t know that its source has been updated.

···

On Fri, Oct 5, 2012 at 10:47 AM, Usjes <oisin_nz@…225…> wrote:

Benjamin Root-2 wrote

On Fri, Oct 5, 2012 at 6:38 AM, Usjes <

oisin_nz@…4225…

wrote:

Does it fail for the example I originally gave?

from pylab import *

plot([1, 2, 3])

savefig(“foobar.emf”)

Ben Root

Yes, it fails even with the simple plot suggested; see log below. I am new

to Python but I did also try inserting the command:

print rgb

preceding the offending line, to get an idea of what the dimensions of ‘rgb’

are but the print statement also fails due to ‘too many values to unpack’

Benjamin Root-2 wrote

Actually, that is very telling... Did you restart python after editing
the
.py file? Python will only load a source file once in a session (unless
explicitly forced to do a reload, but that is not intended for newbies).
So, any changes to any source .py file will not take effect until you
restart your python session. This is different from other languages like
Matlab.

Ben Root

P.S. - The way I am able to deduce this is that when an exception occurs,
the "compiled" code will tell python which lines it came from in the
original source file so that python can display the traceback. If you
edit
the source file to add a line before the line that triggers a traceback,
it
can look like the wrong line is triggering the error because the compiled
code doesn't know that its source has been updated.

Yes, it now works for me , thanks.
I didn't think a restart was necessary as I could see my '[:3]' edit in the
error msg, it hadn't occurred to me that it would source the code for the
error msg from the updated file even though it was out of sync with the
'compiled' version.

Usjes

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/EMF-output-too-many-values-to-unpack-error-tp11466p39277.html
Sent from the matplotlib - users mailing list archive at Nabble.com.