Jupyter: RuntimeError: ... 找不到乳胶

时间:2021-07-01 12:58:33

标签: python matplotlib fonts jupyter-notebook latex

我已经阅读了几乎所有关于问题的解决方案/建议的帖子:

<块引用>

运行时错误:无法使用 tex 处理字符串,因为找不到 Latex

但是我还没有能够解决这个问题。

我使用的是 Windows 10,并尝试了以下所有方法:

  1. 在 Ubuntu 中:
pip install latex
sudo apt-get install dvipng
sudo apt-get install -y texlive texlive-latex-extra texlive-latex-recommended
  1. 在 Jupyter 中:
pip install latex
conda install -c conda-forge jupyter_latex_envs
conda install -c conda-forge/label/cf201901 jupyter_latex_envs
conda install -c conda-forge/label/cf202003 jupyter_latex_envs

当我在 Jupyter 上运行 latex 时,我在列表中看到 pip list

我尝试了上述方法后重新启动了计算机,但无济于事。

我正在尝试的示例非常简单:

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0,10,num=50)
fx = np.exp(-x)*np.cos(x)

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

fig,ax = plt.subplots()
ax.plot(x,fx)
ax.legend(['$e^{-x}cos(x)$'])
ax.set_xlabel(r'$x$')
ax.set_ylabel(r'$f(x)$');

我差点没能逃脱:

plt.rcParams['font.serif'] = 'Times New Roman'
plt.rcParams['font.family'] = "serif"
plt.rcParams['mathtext.fontset'] = "cm"

但是“Computer Modern Roman”不起作用,理想情况下我想让 useTex=True 工作。

有人能指教我吗?

谢谢!

0 个答案:

没有答案
相关问题