gpt4 book ai didi

matplotlib pgf : OSError: No such file or directory in subprocess. py

转载 作者:行者123 更新时间:2023-12-04 11:53:23 25 4
gpt4 key购买 nike

我尝试使用 matplotlib 为 LaTeX 创建一个 pgf 文件:

from matplotlib.pyplot import subplots
from numpy import linspace
x = linspace(0, 100, 30)
fig, ax = subplots(figsize = (10, 6))
ax.scatter(x, x)
fig.tight_layout()
fig.savefig('/home/mark/dicp/python/figure.pgf')

但我得到 OSError: [Errno 2] No such file or directory :
Traceback (most recent call last):
File "visualize/latex_figs.py", line 32, in <module>
fig.savefig('/home/mark/dicp/python/figure.pgf')
File "/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py", line 1421, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backend_bases.py", line 2220, in print_figure
**kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backend_bases.py", line 1957, in print_pgf
return pgf.print_pgf(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pgf.py", line 818, in print_pgf
self._print_pgf_to_fh(fh, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pgf.py", line 797, in _print_pgf_to_fh
RendererPgf(self.figure, fh),
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pgf.py", line 409, in __init__
self.latexManager = LatexManagerFactory.get_latex_manager()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pgf.py", line 223, in get_latex_manager
new_inst = LatexManager()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_pgf.py", line 305, in __init__
cwd=self.tmpdir)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

它还生成输出文件的这一部分:
%% [whole bunch of comments]
\begingroup%
\makeatletter%
\begin{pgfpicture}%
\pgfpathrectangle{\pgfpointorigin}{\pgfqpoint{10.000000in}{6.000000in}}%
\pgfusepath{use as bounding box}%

我不明白什么 OSError: No such file or directory在 subprocesses.py 与任何事情有关...我试图保存的文件是可写的。我是否误解了什么,或者这是我应该报告的错误?

最佳答案

我在尝试运行示例脚本时也遇到了这个问题。问题发生在backend_pgf.py首先尝试使用默认的 LaTeX 命令。似乎 PGF 后端假定它应该使用 xelatex默认情况下。如果你和我的问题一样,那么你有两个选择:

  • 添加 key "pgf.texsystem" : "pdflatex" (或 lualatex ,无论如何)到您的 matplotlib.rcParams .例如,将以下代码段添加到脚本的顶部:
    import matplotlib
    pgf_with_rc_fonts = {"pgf.texsystem": "pdflatex"}
    matplotlib.rcParams.update(pgf_with_rc_fonts)
  • 确保您有 xelatex ,并且它在您的 PATH 上,并将其用作默认的 Latex 命令(即假设您使用的是 Mac 或 Linux 系统,which xelatex 应该返回一个路径)。
  • 关于matplotlib pgf : OSError: No such file or directory in subprocess. py,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20000427/

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