Hello,
I have some problems when trying to save a figure with usetex=True. Sometimes, it is not possible to save the figure when trying to put an xlabel with LaTeX inside.
It works with pylab.xlabel('M$_\odot$') but not with pylab.xlabel('10$^3$ M$_\odot$') (see below). Do you know why ?
In [1]:import matplotlib
In [2]:matplotlib.__version__
Out[2]:'0.87.7'
In [3]:import pylab
In [4]:a=[0,1]
In [5]:pylab.plot(a)
Out[5]:[<matplotlib.lines.Line2D instance at 0xb690472c>]
In [6]:pylab.xlabel('M$_\odot$')
Out[6]:<matplotlib.text.Text instance at 0xb6976d2c>
In [7]:pylab.savefig('toto.eps')
In [8]:matplotlib.rc('text',usetex=True)
In [9]:pylab.plot(a)
Out[9]:[<matplotlib.lines.Line2D instance at 0xb692466c>]
In [10]:pylab.xlabel('M$_\odot$')
Out[10]:<matplotlib.text.Text instance at 0xb6916e2c>
In [11]:pylab.savefig('toto.eps')
In [12]:matplotlib.rc('text',usetex=False)
In [13]:pylab.plot(a)
Out[13]:[<matplotlib.lines.Line2D instance at 0xb655cb8c>]
In [14]:pylab.xlabel('10$^3$ M$_\odot$')
Out[14]:<matplotlib.text.Text instance at 0xb65586ac>
In [15]:pylab.savefig('toto.eps')
In [16]:matplotlib.rc('text',usetex=True)
In [17]:pylab.plot(a)
Out[17]:[<matplotlib.lines.Line2D instance at 0xb657286c>]
In [18]:pylab.xlabel('10$^3$ M$_\odot$')
Out[18]:<matplotlib.text.Text instance at 0xb656af6c>
In [19]:pylab.savefig('toto.eps')
sh: line 1: 16796 Erreur de segmentation gs -dBATCH -dNOPAUSE -r6000 -sDEVICE=pswrite -sPAPERSIZE=letter -sOutputFile="/tmp/f71dbe52628a3f83a77ab494817525c6.ps" "/tmp/f71dbe52628a3f83a77ab494817525c6"
···
"/tmp/f71dbe52628a3f83a77ab494817525c6.output"
---------------------------------------------------------------------------
exceptions.RuntimeError Traceback (most recent call last)
/home/champavert/<ipython console>
/usr/local/lib/python2.4/site-packages/matplotlib/pylab.py in savefig(*args, **kwargs)
812 def savefig(*args, **kwargs):
813 fig = gcf()
--> 814 return fig.savefig(*args, **kwargs)
815 if Figure.savefig.__doc__ is not None:
816 savefig.__doc__ = _shift_string(Figure.savefig.__doc__)
/usr/local/lib/python2.4/site-packages/matplotlib/figure.py in savefig(self, *args, **kwargs)
685 kwargs[key] = rcParams['savefig.%s'%key]
686
--> 687 self.canvas.print_figure(*args, **kwargs)
688
689 def colorbar(self, mappable, cax=None, **kw):
/usr/local/lib/python2.4/site-packages/matplotlib/backends/backend_tkagg.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, **kwargs)
184 if dpi is None: dpi = rcParams['savefig.dpi']
185 agg = self.switch_backends(FigureCanvasAgg)
--> 186 agg.print_figure(filename, dpi, facecolor, edgecolor, orientation,
187 **kwargs)
188 self.figure.set_canvas(self)
/usr/local/lib/python2.4/site-packages/matplotlib/backends/backend_agg.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, **kwargs)
486 ps = self.switch_backends(FigureCanvasPS)
487 ps.print_figure(filename, dpi, facecolor, edgecolor,
--> 488 orientation, **kwargs)
489 elif ext.find('pdf')>=0:
490 from backend_pdf import FigureCanvasPdf
/usr/local/lib/python2.4/site-packages/matplotlib/backends/backend_ps.py in print_figure(self, outfile, dpi, facecolor, edgecolor, orientation, papertype)
1009 # Let's keep the usetex stuff seperate from the generic postscript
1010 self._print_figure_tex(outfile, dpi, facecolor, edgecolor,
-> 1011 orientation, papertype)
1012 else:
1013 if isinstance(outfile, file):
/usr/local/lib/python2.4/site-packages/matplotlib/backends/backend_ps.py in _print_figure_tex(self, outfile, dpi, facecolor, edgecolor, orientation, papertype)
1243 elif rcParams['text.usetex']:
1244 if False: pass # for debugging
-> 1245 else: gs_distill(tmpfile, ext=='.eps', ptype=papertype, bbox=bbox)
1246
1247 if isinstance(outfile, file):
/usr/local/lib/python2.4/site-packages/matplotlib/backends/backend_ps.py in gs_distill(tmpfile, eps, ptype, bbox)
1341 exit_status = os.system(command)
1342 fh = file(outfile)
-> 1343 if exit_status: raise RuntimeError('ghostscript was not able to process \
1344 your image.\nHere is the full report generated by ghostscript:\n\n' + fh.read())
1345 else: verbose.report(fh.read(), 'debug')
RuntimeError: ghostscript was not able to process your image.
Here is the full report generated by ghostscript:
ESP Ghostscript 8.15 (2006-04-19)
Copyright (C) 2004 artofcode LLC, Benicia, CA. All rights reserved.
This software comes with NO WARRANTY: see the file COPYING for details.
Nicolas