matplotlib 无法在Python图中使用乳胶- RuntimeError:LaTeX无法处理以下字符串:b 'lp'

vptzau2j  于 2023-10-24  发布在  Python
关注(0)|答案(2)|浏览(167)

我想使用乳胶的数字标签,但我得到的错误
运行时错误:LaTeX无法处理以下字符串:b 'lp'
以下是LaTeX生成的完整报告:
就是这样(我没有看到任何报告)
编辑:这是我得到的整个错误:

Traceback (most recent call last):
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 197, in __draw_idle_agg
    FigureCanvasAgg.draw(self)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 464, in draw
    self.figure.draw(self.renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\figure.py", line 1144, in draw
    renderer, self, dsu, self.suppressComposite)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\image.py", line 139, in _draw_list_compositing_images
    a.draw(renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 2426, in draw
    mimage._draw_list_compositing_images(renderer, self, dsu)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\image.py", line 139, in _draw_list_compositing_images
    a.draw(renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\axis.py", line 1138, in draw
    renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\axis.py", line 1078, in _get_tick_bboxes
    extent = tick.label1.get_window_extent(renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\text.py", line 967, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\text.py", line 353, in _get_layout
    ismath=False)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 230, in get_text_width_height_descent
    renderer=self)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 676, in get_text_width_height_descent
    dvifile = self.make_dvi(tex, fontsize)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 423, in make_dvi
    report))
RuntimeError: LaTeX was not able to process the following string:
b'lp'
Here is the full report generated by LaTeX:

下面是我的代码:

import numpy as np
from matplotlib import rc
import matplotlib.pyplot as plt
plt.close('all')

rc('text', usetex = True)

mu = np.linspace(0,10,100)
eta = mu**2

fig, ax = plt.subplots()
ax.plot(mu,eta,label= r'$\eta (\mu)$')
ax.set_title('Test')
ax.legend()
  • 我安装了MiKTeX,根据https://docs.alfresco.com/4.2/tasks/fot-addpath.html将其添加到环境变量中。
  • 我检查了MiKTeX的软件包,在“\MiKTeX excecutables”类别中发现了“miktex-dvipng-bin-x64-2.9”。我推断我有一个dvipng。
  • 我下载了Ghostcript,并将其添加到环境变量中。
  • 我试着用texworks编译一个latex脚本到pdf,它工作得很好,从我推断LaTeX安装正确。
  • https://matplotlib.org/1.4.1/users/usetex.html,这是所有我应该需要的...
  • 我尝试删除我的.matplotlib/tex.cache目录
  • 我试着写作
import matplotlib as mpl
mpl.rcParams['text.usetex']=True

而不是

from matplotlib import rc
rc('text', usetex = True)

但结果是一样的

  • 斯维欣
rc('text', usetex = True)

rc('text', usetex = False)

防止错误,但我的标签不是用乳胶写的...
在谷歌上搜索了很多之后,我的想法很短。有人能帮助我吗?
我的配置是:

  • Python 3.6(我在Spyder中运行代码)
  • MiKTeX 2.9
  • Ghostscript 9.50
  • Windows 10
  • 编辑:matplotlib 2.0.2
    编辑:升级到matplotlib 3.1.1,我得到以下错误:
Traceback (most recent call last):
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 304, in _run_checked_subprocess
    stderr=subprocess.STDOUT)
  File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 336, in check_output
    **kwargs).stdout
  File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 403, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 209, in __init__
    super(SubprocessPopen, self).__init__(*args, **kwargs)
  File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 992, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_qt5.py", line 505, in _draw_idle
    self.draw()
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 388, in draw
    self.figure.draw(self.renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\figure.py", line 1709, in draw
    renderer, self, artists, self.suppressComposite)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\image.py", line 135, in _draw_list_compositing_images
    a.draw(renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 2607, in draw
    self._update_title_position(renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 2556, in _update_title_position
    if title.get_window_extent(renderer).ymin < top:
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\text.py", line 890, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\text.py", line 291, in _get_layout
    ismath="TeX" if self.get_usetex() else False)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 201, in get_text_width_height_descent
    s, fontsize, renderer=self)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 448, in get_text_width_height_descent
    dvifile = self.make_dvi(tex, fontsize)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 338, in make_dvi
    texfile], tex)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 308, in _run_checked_subprocess
    'found'.format(command[0])) from exc
RuntimeError: Failed to process string with tex because latex could not be found
Traceback (most recent call last):
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 304, in _run_checked_subprocess
    stderr=subprocess.STDOUT)
  File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 336, in check_output
    **kwargs).stdout
  File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 403, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 209, in __init__
    super(SubprocessPopen, self).__init__(*args, **kwargs)
  File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\Users\Vincent\Anaconda3\lib\subprocess.py", line 992, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_qt5.py", line 505, in _draw_idle
    self.draw()
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 388, in draw
    self.figure.draw(self.renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\figure.py", line 1709, in draw
    renderer, self, artists, self.suppressComposite)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\image.py", line 135, in _draw_list_compositing_images
    a.draw(renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 2607, in draw
    self._update_title_position(renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 2556, in _update_title_position
    if title.get_window_extent(renderer).ymin < top:
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\text.py", line 890, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\text.py", line 291, in _get_layout
    ismath="TeX" if self.get_usetex() else False)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py", line 201, in get_text_width_height_descent
    s, fontsize, renderer=self)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 448, in get_text_width_height_descent
    dvifile = self.make_dvi(tex, fontsize)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 338, in make_dvi
    texfile], tex)
  File "C:\Users\Vincent\Anaconda3\lib\site-packages\matplotlib\texmanager.py", line 308, in _run_checked_subprocess
    'found'.format(command[0])) from exc
RuntimeError: Failed to process string with tex because latex could not be found
rpppsulh

rpppsulh1#

大约第5次我unistalled并重新安装MikTeX,这一次我的问题得到解决.当运行我的Python脚本,三个窗口打开连续要求安装包.我附上这三个窗口的答案截图.接受安装这些包后,我的脚本工作正常.以前,当unistalled并重新安装MikTeX,我已经看到windows要求安装并接受了安装。我不知道为什么这次它工作,而它以前不工作.无论如何,我的问题得到解决卸载和重新安装MiKTeX,运行我的脚本和接受软件包。
Window for installation of a file from type1cm
Window for installation of a file from iftex
Window for installation of a file from zhmetrics

bfrts1fy

bfrts1fy2#

我通过在Ubuntu 18.04上安装texlive-fonts-extra解决了这个问题。
sudo apt-get install texlive-fonts-extra

相关问题