Description
Hello,
If I turn usetex=True, in rcParams and then try to save a figure using plt.savefig("xxx.eps")
I get the error message at the end of the post.
I tracked this down, and the issue is with the temporary file created by tempfile.mkstemp()
in the function _print_figure_tex on backend_ps.py. This file, when the username in windows is long, it is shortened to 6 characters + "~1", then when running latex, the ~ is interpreted as a line break, therefore giving the error.
I perform a simple fix on backend_ps.py, which is simply replace the short version of the username for the full name. This completely solves the problem for me:
fd, tmpfile = mkstemp()
#Fix#
tmplist=tmpfile.split("\\")
tmplist[2]=os.getenv('USERNAME').lower()
tmpfile="\\".join(tmplist)
#####
Do not know how to proceed though in order for this "fix" to be checked/included/discarded...
Thanks!
Now the complete error message ( I changed the visible part of my username to xxxxxx):
import matplotlib.pyplot as plt
plt.rc("text", usetex=True)
plt.savefig("D:/test.eps")
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-3-10b5dc142fe5> in <module>()
----> 1 plt.savefig("D:/test.eps")
c:\python27\lib\site-packages\matplotlib\pyplot.pyc in savefig(*args, **kwargs)
686 def savefig(*args, **kwargs):
687 fig = gcf()
--> 688 res = fig.savefig(*args, **kwargs)
689 fig.canvas.draw_idle() # need this if 'transparent=True' to reset colors
690 return res
c:\python27\lib\site-packages\matplotlib\figure.pyc in savefig(self, *args, **kwargs)
1537 self.set_frameon(frameon)
1538
-> 1539 self.canvas.print_figure(*args, **kwargs)
1540
1541 if frameon:
c:\python27\lib\site-packages\matplotlib\backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
2228 orientation=orientation,
2229 bbox_inches_restore=_bbox_inches_restore,
-> 2230 **kwargs)
2231 finally:
2232 if bbox_inches and restore_bbox:
c:\python27\lib\site-packages\matplotlib\backends\backend_ps.pyc in print_eps(self, outfile, *args, **kwargs)
993
994 def print_eps(self, outfile, *args, **kwargs):
--> 995 return self._print_ps(outfile, 'eps', *args, **kwargs)
996
997 def _print_ps(self, outfile, format, *args, **kwargs):
c:\python27\lib\site-packages\matplotlib\backends\backend_ps.pyc in _print_ps(self, outfile, format, *args, **kwargs)
1017 self._print_figure_tex(outfile, format, imagedpi, facecolor, edgecolor,
1018 orientation, isLandscape, papertype,
-> 1019 **kwargs)
1020 else:
1021 self._print_figure(outfile, format, imagedpi, facecolor, edgecolor,
c:\python27\lib\site-packages\matplotlib\backends\backend_ps.pyc in _print_figure_tex(self, outfile, format, dpi, facecolor, edgecolor, orientation, isLandscape, papertype, **kwargs)
1378 font_preamble,
1379 custom_preamble, paperWidth, paperHeight,
-> 1380 orientation)
1381
1382 if rcParams['ps.usedistiller'] == 'ghostscript':
c:\python27\lib\site-packages\matplotlib\backends\backend_ps.pyc in convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble, paperWidth, paperHeight, orientation)
1476 if exit_status:
1477 raise RuntimeError('LaTeX was not able to process your file:\
-> 1478 \nHere is the full report generated by LaTeX: \n\n%s'% fh.read())
1479 else:
1480 verbose.report(fh.read(), 'debug')
RuntimeError: LaTeX was not able to process your file:
Here is the full report generated by LaTeX:
This is pdfTeX, Version 3.14159265-2.6-1.40.16 (MiKTeX 2.9)
entering extended mode
! I can't find file `c:/users/xxxxxx'.
<to be read again>
\protect
<*> c:/users/xxxxxx~
1/appdata/local/temp/tmpykvykd.tex
Please type another input file name
! Emergency stop.
<to be read again>
\protect
<*> c:/users/xxxxxx~
1/appdata/local/temp/tmpykvykd.tex
No pages of output.
Transcript written on texput.log.