latex problem

Dear list,

activating latex rendering by change of the matplotlibrc variable
'text.usetex' to true gives me the following error. I am using
matplotlib 0.84 using python 2.4.1 on linux. Does anyknow know how to
solve this? This problem doesn't appear for the simple plot command:

        from matplotlib.pylab import *
        title(r'$\rho$')
        plot([1,2,3,4])
        show()

But when I plot multiple lines using the following approach:

        from matplotlib import pylab
        def plotroc(x,y, label=None):
            pylab.figure(0)
            pylab.plot(x,y,label=label)
            pylab.xlabel('1-specificity')
            pylab.ylabel('sensitivity')
            pylab.axis(xmin=0, xmax=1, ymin=0, ymax=1)
        
        plotroc([1,2,3,4],[4,4,2,1],label='a')
        plotroc([1,2,3,4],[4,3,2,1],label='b')

        pylab.savefig('test.eps')
        
matplotlib comes with the following message:

        exceptions.OSError Traceback
        (most recent call last)
        
        /usr/local/lib/python2.4/site-packages/matplotlib/backends/backend_gtk.py in expose_event(self, widget, event)
            316 x, y, w, h = self.allocation
            317 self._pixmap_prepare (w, h)
        --> 318 self._render_figure(self._pixmap, w, h)
            319 self._need_redraw = False
            320
        
        ...
        
        /usr/local/lib/python2.4/site-packages/matplotlib/texmanager.py
        in make_dvi(self, tex, force)
            125 # dir and move it if necessary and then cleanup
            126 if os.path.exists(dvibase):
        --> 127 os.rename(dvibase, dvifile)
            128 for fname in glob.glob(prefix+'*'):
            129 os.remove(fname)
        
        OSError: [Errno 18] Invalid cross-device link
        
Thanks in advance,

Joost

Joost van Evert wrote:

Dear list,

        /usr/local/lib/python2.4/site-packages/matplotlib/texmanager.py
        in make_dvi(self, tex, force)
            125 # dir and move it if necessary and then cleanup
            126 if os.path.exists(dvibase):
        --> 127 os.rename(dvibase, dvifile)
            128 for fname in glob.glob(prefix+'*'):
            129 os.remove(fname)
                OSError: [Errno 18] Invalid cross-device link

This could be considered a matplolib bug, or a python one, depending on your perspective. os.rename() doesn't work across partitions, which makes it (IMHO) worse than useless. You have to either protect on all uses against this exception, or use shutil.move(), which does work across partitions:

Definition: shutil.move(src, dst)
Docstring:
     Recursively move a file or directory to another location.

     If the destination is on our current filesystem, then simply use
     rename. Otherwise, copy src to the dst and then remove src.
     A lot more could be done here... A look at a mv.c shows a lot of
     the issues this implementation glosses over.

So if you think that Python is OK in having such a useless os.rename, then it's a matplotlib bug (this is, after all, known os.rename behavior). In the short term, though, matplotlib would be well advised to use only os.rename when doing renamings *known to be in the same directory*. Anytime you use rename to actually move things, this problem can appear (and it's configuration-specific, hence impossible to detect during in-house testing).

Cheers,

f

What does this mean in matplotlib practice? Which partitions does one
put plotting scripts, that contain latex formulae, to prevent this
error?

Greets,
Joost

···

On Mon, 2005-10-10 at 12:17 -0600, Fernando Perez wrote:

This could be considered a matplolib bug, or a python one, depending on your
perspective. os.rename() doesn't work across partitions, which makes it
(IMHO) worse than useless. You have to either protect on all uses against this
exception, or use shutil.move(), which does work across partitions: