Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib error, [Errno 2] No such file or directory: 'latex': 'latex'?

Tags:

matplotlib

When I try running the very simple code snippet from www.matplotlib.org,

from matplotlib import rc
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
## for Palatino and other serif fonts use:
#rc('font',**{'family':'serif','serif':['Palatino']})
rc('text', usetex=True)

import numpy as np
import matplotlib.pyplot as plt


# Example data
t = np.arange(0.0, 1.0 + 0.01, 0.01)
s = np.cos(4 * np.pi * t) + 2

plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plt.plot(t, s)

plt.xlabel(r'\textbf{time} (s)')
plt.ylabel(r'\textit{voltage} (mV)',fontsize=16)
plt.title(r"\TeX\ is Number "
          r"$\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!",
          fontsize=16, color='gray')
# Make room for the ridiculously large title.
plt.subplots_adjust(top=0.8)

plt.savefig('tex_demo')
plt.show()

This is highly unusual this code has worked for me before and I cannot figure out what the issue is. The error message that I receive is enormous and shown below. Does anybody know what the issue might be?

Thanks!!

Traceback (most recent call last):

File "/Users/evan/anaconda3/lib/python3.6/site-packages/IPython/core/formatters.py", line 332, in call return printer(obj)

File "/Users/evan/anaconda3/lib/python3.6/site-packages/IPython/core/pylabtools.py", line 237, in png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))

File "/Users/evan/anaconda3/lib/python3.6/site-packages/IPython/core/pylabtools.py", line 121, in print_figure fig.canvas.print_figure(bytes_io, **kw)

File "/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 2216, in print_figure **kwargs)

File "/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 507, in print_png FigureCanvasAgg.draw(self)

File "/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 430, in draw self.figure.draw(self.renderer)

File "/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper return draw(artist, renderer, *args, **kwargs)

File "/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/figure.py", line 1299, in draw renderer, self, artists, self.suppressComposite)

File "/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/image.py", line 138, in _draw_list_compositing_images a.draw(renderer)

File "/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper return draw(artist, renderer, *args, **kwargs)

File "/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 2437, in draw mimage._draw_list_compositing_images(renderer, self, artists)

File "/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/image.py", line 138, in _draw_list_compositing_images a.draw(renderer)

File "/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper return draw(artist, renderer, *args, **kwargs)

File "/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/axis.py", line 1135, in draw renderer)

File "/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/axis.py", line 1075, in _get_tick_bboxes extent = tick.label1.get_window_extent(renderer)

File "/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/text.py", line 933, in get_window_extent bbox, info, descent = self._get_layout(self._renderer)

File "/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/text.py", line 308, in _get_layout ismath=False)

File "/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 226, in get_text_width_height_descent s, fontsize, renderer=self)

File "/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/texmanager.py", line 602, in get_text_width_height_descent dvifile = self.make_dvi(tex, fontsize)

File "/Users/evan/anaconda3/lib/python3.6/site-packages/matplotlib/texmanager.py", line 393, in make_dvi stderr=subprocess.STDOUT)

File "/Users/evan/anaconda3/lib/python3.6/subprocess.py", line 336, in check_output **kwargs).stdout

File "/Users/evan/anaconda3/lib/python3.6/subprocess.py", line 403, in run with Popen(*popenargs, **kwargs) as process:

File "/Users/evan/anaconda3/lib/python3.6/subprocess.py", line 709, in init restore_signals, start_new_session)

File "/Users/evan/anaconda3/lib/python3.6/subprocess.py", line 1344, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename)

FileNotFoundError: [Errno 2] No such file or directory: 'latex': 'latex'

like image 390
Evan Avatar asked Mar 11 '18 19:03

Evan


1 Answers

For linux:

 sudo yum install latex
 sudo yum install dvipng

For Window: install texlive.

ref. https://matplotlib.org/tutorials/text/usetex.html?highlight=latex

like image 75
zhenghy Avatar answered Oct 20 '22 13:10

zhenghy