Я пытаюсь использовать латексный интерпретатор для надписей.Я генерирую свои цифры, используя библиотеку matplotlib.
У меня проблемы с поиском ответа на эту распространенную проблему.Я вижу много ответов, предлагающих добавить к пути латекс, как нам это сделать?
Я пытался установить Ghostscript, обновить matplotlib и т. Д., Но безрезультатно.Любая помощь по этому вопросу будет принята с благодарностью.
Фрагмент кода для тестирования:
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()
Вот результат выполненного кода:
Traceback (most recent call last):
File "/Users/selih/anaconda3/lib/python3.6/site-packages/IPython/core/formatters.py", line 341, in __call__
return printer(obj)
File "/Users/selih/anaconda3/lib/python3.6/site-packages/IPython/core/pylabtools.py", line 241, in <lambda>
png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
File "/Users/selih/anaconda3/lib/python3.6/site-packages/IPython/core/pylabtools.py", line 125, in print_figure
fig.canvas.print_figure(bytes_io, **kw)
File "/Users/selih/anaconda3/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 2212, in print_figure
**kwargs)
File "/Users/selih/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 513, in print_png
FigureCanvasAgg.draw(self)
File "/Users/selih/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 433, in draw
self.figure.draw(self.renderer)
File "/Users/selih/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/Users/selih/anaconda3/lib/python3.6/site-packages/matplotlib/figure.py", line 1475, in draw
renderer, self, artists, self.suppressComposite)
File "/Users/selih/anaconda3/lib/python3.6/site-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images
a.draw(renderer)
File "/Users/selih/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/Users/selih/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 2607, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "/Users/selih/anaconda3/lib/python3.6/site-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images
a.draw(renderer)
File "/Users/selih/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py", line 55, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/Users/selih/anaconda3/lib/python3.6/site-packages/matplotlib/axis.py", line 1192, in draw
renderer)
File "/Users/selih/anaconda3/lib/python3.6/site-packages/matplotlib/axis.py", line 1130, in _get_tick_bboxes
extent = tick.label1.get_window_extent(renderer)
File "/Users/selih/anaconda3/lib/python3.6/site-packages/matplotlib/text.py", line 922, in get_window_extent
bbox, info, descent = self._get_layout(self._renderer)
File "/Users/selih/anaconda3/lib/python3.6/site-packages/matplotlib/text.py", line 309, in _get_layout
ismath=ismath)
File "/Users/selih/anaconda3/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py", line 232, in get_text_width_height_descent
s, fontsize, renderer=self)
File "/Users/selih/anaconda3/lib/python3.6/site-packages/matplotlib/texmanager.py", line 501, in get_text_width_height_descent
dvifile = self.make_dvi(tex, fontsize)
File "/Users/selih/anaconda3/lib/python3.6/site-packages/matplotlib/texmanager.py", line 365, in make_dvi
texfile], tex)
File "/Users/selih/anaconda3/lib/python3.6/site-packages/matplotlib/texmanager.py", line 335, in _run_checked_subprocess
stderr=subprocess.STDOUT)
File "/Users/selih/anaconda3/lib/python3.6/subprocess.py", line 356, in check_output
**kwargs).stdout
File "/Users/selih/anaconda3/lib/python3.6/subprocess.py", line 423, in run
with Popen(*popenargs, **kwargs) as process:
File "/Users/selih/anaconda3/lib/python3.6/subprocess.py", line 729, in __init__
restore_signals, start_new_session)
File "/Users/selih/anaconda3/lib/python3.6/subprocess.py", line 1364, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'latex': 'latex'
<Figure size 432x288 with 1 Axes>
Я считаю, что это довольно распространенная ошибка, ноответы на ее решение не дали мне инструментов для ее решения.Буду признателен за любую помощь по добавлению латекса, dvipng в мой PATH.