emf backend doesn't work with StringIO #1773

tomkcook opened this Issue Feb 21, 2013 · 2 comments


None yet

2 participants


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)
import StringIO
s = StringIO.StringIO()
f.savefig(s, format='emf')


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
  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
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_emf.py", line 180, in save
  File "C:\Python27\lib\site-packages\pyemf.py", line 2230, in save
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.

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.


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