[Matplotlib-users] TeX + QT4Agg = Broken (Mac OS X)
Hi, I just ran into the following Bug: When choosing Qt4Agg as my backend in the matplotlibrc, using TeX will break matplotlib. When choosing backend: MacOSX, everything works fine. The QT4Agg backend also works fine as long as I'm not using TeX. Here is a fairly minimal example: # file: killqtmpl.py # import pylab as plt import time print This works plt.rcdefaults() plt.plot([1,2,3]) plt.show() time.sleep(2) plt.close() print This won't work with qt4agg plt.rc('font', family='sans-serif') plt.rc('text', usetex=True) plt.rcParams['text.latex.preamble']=r \usepackage[tx]{sfmath} \usepackage{helvet} plt.plot([1,2,3]) plt.show() time.sleep(2) plt.close() print This won't either plt.rc('font', family='serif') plt.rcParams['text.latex.preamble']=r\usepackage{mathptmx} plt.plot([1,2,3]) plt.show() # So, when i run the above script using the MacOSX backend, it displays the same figure (a blue line) three times and outputs: --- This works This won't work with qt4agg This won't either --- Now when using Qt4Agg, only the first figure will get displayed and the following error messages appear: --- In [1]: run killqtmpl.py This works This won't work with qt4agg ERROR: An unexpected error occurred while tokenizing input The following traceback may be corrupted or invalid The error message is: ('EOF in multi-line statement', (17, 0)) ERROR: An unexpected error occurred while tokenizing input The following traceback may be corrupted or invalid The error message is: ('EOF in multi-line statement', (15, 0)) --- AttributeErrorTraceback (most recent call last) /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_qt4agg.pyc in paintEvent(self, e) 80 81 if self.replot: --- 82 FigureCanvasAgg.draw(self) 83 self.replot = False 84 /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in draw(self) 399 400 self.renderer = self.get_renderer() -- 401 self.figure.draw(self.renderer) 402 403 def get_renderer(self): /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs) 53 def draw_wrapper(artist, renderer, *args, **kwargs): 54 before(artist, renderer) --- 55 draw(artist, renderer, *args, **kwargs) 56 after(artist, renderer) 57 /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.pyc in draw(self, renderer) 882 dsu.sort(key=itemgetter(0)) 883 for zorder, func, args in dsu: -- 884 func(*args) 885 886 renderer.close_group('figure') /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs) 53 def draw_wrapper(artist, renderer, *args, **kwargs): 54 before(artist, renderer) --- 55 draw(artist, renderer, *args, **kwargs) 56 after(artist, renderer) 57 /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes.pyc in draw(self, renderer, inframe) 1981 1982 for zorder, a in dsu: - 1983 a.draw(renderer) 1984 1985 renderer.close_group('axes') /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs) 53 def draw_wrapper(artist, renderer, *args, **kwargs): 54 before(artist, renderer) --- 55 draw(artist, renderer, *args, **kwargs) 56 after(artist, renderer) 57 /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axis.pyc in draw(self, renderer, *args, **kwargs) 1035 1036 ticks_to_draw = self._update_ticks(renderer) - 1037 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw, renderer) 1038 1039 for tick in ticks_to_draw: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axis.pyc in _get_tick_bboxes(self, ticks, renderer) 986 for tick in ticks: 987 if tick.label1On and tick.label1.get_visible(): -- 988 extent = tick.label1.get_window_extent(renderer) 989 ticklabelBoxes.append(extent) 990 if tick.label2On and tick.label2.get_visible():
Re: [Matplotlib-users] TeX + QT4Agg = Broken (Mac OS X)
Felix Patzelt fe...@neuro.uni-bremen.de writes: I just ran into the following Bug: When choosing Qt4Agg as my backend in the matplotlibrc, using TeX will break matplotlib. Could you run your test script with --verbose-debug, redirect the output to a file and send it to me (off-list; it will be a large file)? -- Jouni K. Seppänen http://www.iki.fi/jks -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] TeX + QT4Agg = Broken (Mac OS X)
Jouni K. Seppänen j...@iki.fi writes: Felix Patzelt fe...@neuro.uni-bremen.de writes: I just ran into the following Bug: When choosing Qt4Agg as my backend in the matplotlibrc, using TeX will break matplotlib. Could you run your test script with --verbose-debug, redirect the output to a file and send it to me (off-list; it will be a large file)? Got it, thanks. This looks really odd: with both MacOSX and QT4Agg backends, kpsewhich finds some TeX-related files, but with QT4Agg some files are not found. It doesn't look like a simple matter of wrong paths or anything like that, because then it would not find any files. We have had multiple problems related to Qt and subprocesses. Some Googling suggests that such problems are quite prevalent and might not be easy to solve. -- Jouni K. Seppänen http://www.iki.fi/jks -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] TeX + QT4Agg = Broken (Mac OS X)
Felix Patzelt fe...@neuro.uni-bremen.de writes: Matplotlib-Version: 1.1.0 If that's the released version and not something from git, it does not have one possibly related fix. Could you try cherry-picking commit 09293bf from github, or applying the following patch. commit 09293bf96f79f305d96ae4070dc89537efb9fb17 Author: Jouni K. Seppänen j...@iki.fi Date: Tue Dec 27 20:21:34 2011 +0200 Work around subprocess EINTR bug; fixes issue #633 The bug http://bugs.python.org/issue12493 is present in some Python versions. The _read_nointr function has been unused since b03a908 (it did not work on Windows). diff --git a/CHANGELOG b/CHANGELOG index 9f5c700..e2a2b9d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +2011-12-27 Work around an EINTR bug in some versions of subprocess. - JKS + 2011-08-18 Change api of Axes.get_tightbbox and add an optional keyword parameter *call_axes_locator*. - JJL diff --git a/lib/matplotlib/dviread.py b/lib/matplotlib/dviread.py index 85fa70f..8a6dbd2 100644 --- a/lib/matplotlib/dviread.py +++ b/lib/matplotlib/dviread.py @@ -835,23 +835,17 @@ def find_tex_file(filename, format=None): matplotlib.verbose.report('find_tex_file(%s): %s' \ % (filename,cmd), 'debug') -pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE) +# stderr is unused, but reading it avoids a subprocess optimization +# that breaks EINTR handling in some Python versions: +# http://bugs.python.org/issue12493 +# https://github.com/matplotlib/matplotlib/issues/633 +pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, +stderr=subprocess.PIPE) result = pipe.communicate()[0].rstrip() matplotlib.verbose.report('find_tex_file result: %s' % result, 'debug') return result -def _read_nointr(pipe, bufsize=-1): -while True: -try: -return pipe.read(bufsize) -except OSError, e: -if e.errno == errno.EINTR: -continue -else: -raise - - # With multiple text objects per figure (e.g. tick labels) we may end # up reading the same tfm and vf files many times, so we implement a # simple cache. TODO: is this worth making persistent? -- Jouni K. Seppänen http://www.iki.fi/jks -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users