emf backend doesn't work with StringIO #1773

Closed
tomkcook opened this Issue Feb 21, 2013 · 2 comments

Projects

None yet

2 participants

@tomkcook

Matplotlib version: 1.1.1
Python version: 2.7 64-bit
OS: Windows 7 64-bit

Code to reproduce the problem:

import matplotlib.pylab
f = matplotlib.pylab.figure()
ax = f.add_subplot(111)
ax.plot(range(0,10))
import StringIO
s = StringIO.StringIO()
f.savefig(s, format='emf')

Output:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 1185, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_qt4agg.py", line 138, in print_figure
    FigureCanvasAgg.print_figure(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\backend_bases.py", line 2021, in print_figure
    **kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\backend_bases.py", line 1779, in print_emf
    return emf.print_emf(*args, **kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_emf.py", line 718, in print_emf
    renderer.save()
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_emf.py", line 180, in save
    self.emf.save(self.outfile)
  File "C:\Python27\lib\site-packages\pyemf.py", line 2230, in save
    fh=open(self.filename,"wb")
TypeError: coercing to Unicode: need string or buffer, instance found

This works with other backends such as EPS and PNG but this bug makes it impossible (AFAICT) to copy vector images of plots to the Windows clipboard.

@WeatherGod
Matplotlib Developers member

As you can see in the traceback, it is the pyemf package that is having the problem because it is assuming that the input is a filename. I am not familiar with the pyemf package and whether it has any existing support for StringIO or not, but you should probably file this bug with them.

@tomkcook

Okay, will do.

@WeatherGod WeatherGod closed this Feb 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment