gpt4 book ai didi

Matplotlib 错误,[Errno 2] 没有那个文件或目录 : 'latex' : 'latex' ?

转载 作者:行者123 更新时间:2023-12-04 15:51:02 25 4
gpt4 key购买 nike

当我尝试运行来自 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()

这是非常不寻常的,这段代码以前对我有用,我无法弄清楚问题是什么。我收到的错误消息很大,如下所示。有人知道可能是什么问题吗?

谢谢!!

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'

最佳答案

对于Linux:

 sudo yum install latex
sudo yum install dvipng

对于窗口:
安装 texlive。

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

关于Matplotlib 错误,[Errno 2] 没有那个文件或目录 : 'latex' : 'latex' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49224164/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com