Hello,
I’ve been having some troubles with LaTeX in matplotlib. My example script:
#!/usr/bin/env python2
#-- coding: utf-8 --
author = ‘Pawel Chojnacki’
copyright =‘Copyleft 2013 Pawel Chojnacki’
version = ‘1.0’
date = ‘29-03-2013’
license = ‘GPLv3’
import numpy as np
import matplotlib as mpl # Zmiana ustawien LaTeXa
mpl.rcParams[‘text.latex.preamble’].append(r’\usepackage{amsmath}’)
#~ mpl.rcParams[‘text.latex.preamble’] = r’\usepackage{amsmath}’
#~ mpl.rcParams[‘text.latex.preamble’]=[r"\usepackage{amsmath}"]
#~ mpl.rcParams[‘math.usetex’] = True
print mpl.rcParams[‘text.latex.preamble’]
import pylab as py
py.axhspan(8400,8730,alpha=0.15)
py.title(u’Wyniki eksperymentu pomiaru gęstości ciała stałego\n’,size=‘large’,family=‘serif’)
py.ylabel((u’Gęstość ciała stałego ’ + r’$\frac{kg}{m^3}$’),size=‘large’,family=‘serif’)
#~ py.ylabel((r’$\text{lol}$’),size=‘large’,family=‘serif’)
py.ylabel((r’$\text{lol}$’),size=‘large’,family=‘serif’)
py.xlabel(u’Metoda pomiaru’,size=‘large’,family=‘serif’)
py.grid(True)
py.show()
Gives me the following output:
[’’, ‘\usepackage{amsmath}’]
Exception in Tkinter callback
Traceback (most recent call last):
File “/usr/lib/python2.7/lib-tk/Tkinter.py”, line 1437, in call
return self.func(*args)
File “/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py”, line 236, in resize
self.show()
File “/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py”, line 239, in draw
FigureCanvasAgg.draw(self)
File “/usr/lib/pymodules/python2.7/matplotlib/backends/backend_agg.py”, line 421, in draw
self.figure.draw(self.renderer)
File “/usr/lib/pymodules/python2.7/matplotlib/artist.py”, line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File “/usr/lib/pymodules/python2.7/matplotlib/figure.py”, line 898, in draw
func(*args)
File “/usr/lib/pymodules/python2.7/matplotlib/artist.py”, line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File “/usr/lib/pymodules/python2.7/matplotlib/axes.py”, line 1997, in draw
a.draw(renderer)
File “/usr/lib/pymodules/python2.7/matplotlib/artist.py”, line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File “/usr/lib/pymodules/python2.7/matplotlib/axis.py”, line 1054, in draw
self.label.draw(renderer)
File “/usr/lib/pymodules/python2.7/matplotlib/artist.py”, line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File “/usr/lib/pymodules/python2.7/matplotlib/text.py”, line 526, in draw
bbox, info = self._get_layout(renderer)
File “/usr/lib/pymodules/python2.7/matplotlib/text.py”, line 309, in _get_layout
ismath=ismath)
File “/usr/lib/pymodules/python2.7/matplotlib/backends/backend_agg.py”, line 193, in get_text_width_height_descent
self.mathtext_parser.parse(s, self.dpi, prop)
File “/usr/lib/pymodules/python2.7/matplotlib/mathtext.py”, line 2999, in parse
box = self._parser.parse(s, font_output, fontsize, dpi)
File “/usr/lib/pymodules/python2.7/matplotlib/mathtext.py”, line 2357, in parse
self._expression.parseString(s)
File “/usr/lib/pymodules/python2.7/matplotlib/pyparsing.py”, line 1048, in parseString
loc, tokens = self._parse( instring, 0 )
File “/usr/lib/pymodules/python2.7/matplotlib/pyparsing.py”, line 981, in _parseCache
value = self._parseNoCache( instring, loc, doActions, callPreParse )
File “/usr/lib/pymodules/python2.7/matplotlib/pyparsing.py”, line 924, in _parseNoCache
loc,tokens = self.parseImpl( instring, preloc, doActions )
File “/usr/lib/pymodules/python2.7/matplotlib/pyparsing.py”, line 2559, in parseImpl
return self.expr._parse( instring, loc, doActions, callPreParse=False )
File “/usr/lib/pymodules/python2.7/matplotlib/pyparsing.py”, line 981, in _parseCache
value = self._parseNoCache( instring, loc, doActions, callPreParse )
File “/usr/lib/pymodules/python2.7/matplotlib/pyparsing.py”, line 924, in _parseNoCache
loc,tokens = self.parseImpl( instring, preloc, doActions )
File “/usr/lib/pymodules/python2.7/matplotlib/pyparsing.py”, line 2307, in parseImpl
loc, exprtokens = e._parse( instring, loc, doActions )
File “/usr/lib/pymodules/python2.7/matplotlib/pyparsing.py”, line 981, in _parseCache
value = self._parseNoCache( instring, loc, doActions, callPreParse )
File “/usr/lib/pymodules/python2.7/matplotlib/pyparsing.py”, line 924, in _parseNoCache
loc,tokens = self.parseImpl( instring, preloc, doActions )
File “/usr/lib/pymodules/python2.7/matplotlib/pyparsing.py”, line 2672, in parseImpl
loc, tokens = self.expr._parse( instring, loc, doActions, callPreParse=False )
File “/usr/lib/pymodules/python2.7/matplotlib/pyparsing.py”, line 981, in _parseCache
value = self._parseNoCache( instring, loc, doActions, callPreParse )
File “/usr/lib/pymodules/python2.7/matplotlib/pyparsing.py”, line 924, in _parseNoCache
loc,tokens = self.parseImpl( instring, preloc, doActions )
File “/usr/lib/pymodules/python2.7/matplotlib/pyparsing.py”, line 2307, in parseImpl
loc, exprtokens = e._parse( instring, loc, doActions )
File “/usr/lib/pymodules/python2.7/matplotlib/pyparsing.py”, line 981, in _parseCache
value = self._parseNoCache( instring, loc, doActions, callPreParse )
File “/usr/lib/pymodules/python2.7/matplotlib/pyparsing.py”, line 924, in _parseNoCache
loc,tokens = self.parseImpl( instring, preloc, doActions )
File “/usr/lib/pymodules/python2.7/matplotlib/pyparsing.py”, line 2416, in parseImpl
ret = e._parse( instring, loc, doActions )
File “/usr/lib/pymodules/python2.7/matplotlib/pyparsing.py”, line 981, in _parseCache
value = self._parseNoCache( instring, loc, doActions, callPreParse )
File “/usr/lib/pymodules/python2.7/matplotlib/pyparsing.py”, line 950, in _parseNoCache
tokens = fn( instring, tokensStart, retTokens )
File “/usr/lib/pymodules/python2.7/matplotlib/mathtext.py”, line 2050, in raise_error
raise ParseFatalException(msg + “\n” + s)
ParseFatalException: Expected end of math ‘$’
$\text{lol}$ (at char 0), (line:1, col:1)
And a blank window. The same line - $\text{lol}$ works pretty well in pure LaTeX. While the package seems loaded, matplotlib doesn’t send the command as it’s supposed to. Why is that?
Thanks in advance,
Pawel