32

This is the error I'm getting from the function I'll provide at the bottom:

'latex' is not recognized as an internal or external command,
operable program or batch file.
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\python27\lib\lib-tk\Tkinter.py", line 1486, in __call__
    return self.func(*args)
  File "C:\python27\lib\site-packages\matplotlib\backends\backend_tkagg.py", lin
e 278, in resize
    self.show()
  File "C:\python27\lib\site-packages\matplotlib\backends\backend_tkagg.py", lin
e 349, in draw
    FigureCanvasAgg.draw(self)
  File "C:\python27\lib\site-packages\matplotlib\backends\backend_agg.py", line
469, in draw
    self.figure.draw(self.renderer)
  File "C:\python27\lib\site-packages\matplotlib\artist.py", line 59, in draw_wr
apper
    draw(artist, renderer, *args, **kwargs)
  File "C:\python27\lib\site-packages\matplotlib\figure.py", line 1079, in draw
    func(*args)
  File "C:\python27\lib\site-packages\matplotlib\artist.py", line 59, in draw_wr
apper
    draw(artist, renderer, *args, **kwargs)
  File "C:\python27\lib\site-packages\matplotlib\axes\_base.py", line 2092, in d
raw
    a.draw(renderer)
  File "C:\python27\lib\site-packages\matplotlib\artist.py", line 59, in draw_wr
apper
    draw(artist, renderer, *args, **kwargs)
  File "C:\python27\lib\site-packages\matplotlib\axis.py", line 1116, in draw
    renderer)
  File "C:\python27\lib\site-packages\matplotlib\axis.py", line 1065, in _get_ti
ck_bboxes
    extent = tick.label1.get_window_extent(renderer)
  File "C:\python27\lib\site-packages\matplotlib\text.py", line 741, in get_wind
ow_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "C:\python27\lib\site-packages\matplotlib\text.py", line 311, in _get_lay
out
    ismath=False)
  File "C:\python27\lib\site-packages\matplotlib\backends\backend_agg.py", line
223, in get_text_width_height_descent
    renderer=self)
  File "C:\python27\lib\site-packages\matplotlib\texmanager.py", line 670, in ge
t_text_width_height_descent
    dvifile = self.make_dvi(tex, fontsize)
  File "C:\python27\lib\site-packages\matplotlib\texmanager.py", line 417, in ma
ke_dvi
    report))
RuntimeError: LaTeX was not able to process the following string:
'lp'
Here is the full report generated by LaTeX:

This is the function I'm using that creates the above error:

def Derivative( inputArrayList,rowNumber_from_top ):
    for image in inputArrayList:
        rowValues = image[0][rowNumber_from_top]
        for i in range(len(rowValues)):         
            # Perform the difference derivative estimation
            if i == 0 or i == (len(rowValues) - 1):
                rowValues[ i ] = 0 # set edges to 0
            else:
                derivative = (rowValues[ i+1 ] - rowValues[ i-1 ])/(2.0)
                rowValues[ i ] = derivative
        plt.rc('text', usetex=True)
        plt.rc('font', family='serif')
        plt.plot(rowValues,color="k")
        plt.ylim( (0,image.max() + 10.0) )
        plt.title(r"$\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$")
        plt.show()

Notice the line plt.title(r"$\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$"). I've taken this from the first graph on Matplotlib's site (and I've tried running that program as well that they provide) and I cannot seem to get it to work. I'm almost certain it's a simple fix (like maybe I'm missing a LaTeX module or something?).

The whole goal was to be able to use the command \displaystyle in the title and labels of the plot to make fractions larger.

I apologize if this is a duplicate (although I can't find a similar issue), I just need a pointer to get me going in the right direction.

Thank you for your time,

Brandon

bjd2385
  • 2,013
  • 4
  • 26
  • 47
  • 1
    Was there anything after 'Here is the full report generated by LaTeX:'? You might also see if this is helpful: http://stackoverflow.com/questions/11354149/python-unable-to-render-tex-in-matplotlib – Amy Teegarden Jul 03 '15 at 21:36
  • @AmyTeegarden Unfortunately, no, after 'Here is the full report generated by LaTeX:' it was blank. Thanks for the link! I'll look into type1cm. – bjd2385 Jul 03 '15 at 23:19
  • Can you process that line in LaTeX directly, not running through matplotlib? Can you process it if it doesn't invoke `\displaystyle`? Can you run the Matplotlib gallery sample code that uses LaTeX? – cphlewis Jul 04 '15 at 06:11
  • 2
    Did anyone ever find an answer to this? I am having the same problem. Have tried installing the relevant packages and a lot of googling. – Wade Bratz Aug 08 '16 at 17:09
  • 3
    @WadeBratz I think this was the solution: http://stackoverflow.com/a/11357765/3928184 – bjd2385 Aug 08 '16 at 18:04
  • Possible duplicate of [Python: Unable to Render Tex in Matplotlib](https://stackoverflow.com/questions/11354149/python-unable-to-render-tex-in-matplotlib) – Mister_Tom Aug 03 '17 at 16:26
  • It worked for me, when I commented the lines that start with `plt.rc` – Anwarvic Aug 24 '18 at 14:18

2 Answers2

20

It seems you are missing a package for the dvi rendering. On debian-based distributions, this should suffice to get all the needed packages:

sudo apt-get install texlive-latex-extra texlive-fonts-recommended dvipng cm-super
ezatterin
  • 626
  • 5
  • 17
  • 2
    any idea about the mac ? – Ayan Mitra Jul 26 '20 at 04:56
  • 3
    For more recent versions of Matplotlib, you also need to install cm-super `sudo apt-get install cm-super` – varagrawal Aug 06 '20 at 05:46
  • 3
    If anyone has the same problem on MacOSX, I updated all tex packages (by going to `Tex Live Utility` app that is part of MacTeX --> updates tab --> select all --> right click and update) and that seems to have fixed it. I am not able to pinpoint as to which package was the problem, but at least I thought it is good to know that updating everything fixes it. – Vivek V K Sep 20 '20 at 20:33
0

You should test if you have latex installed. For that, open a terminal and type

which latex

The output should be a path to your latex binary. If none is found, try to install a latex distribution. The procedure for this depends on your operating system, Ubuntu for example has a couple of packages for this.

Harpe
  • 316
  • 1
  • 9