我想在matplotlib图形中使用乳胶作为标签。我正在使用Mac OS X和thonny。我下载了一个测试程序,但是每次出现错误:
RuntimeError:找不到乳胶命令。安装“ xelatex”或将pgf.texsystem更改为所需的命令。
我认为这是路径错误...
我还试图更改路径
os.environ["PATH"] += os.pathsep + '/usr/local/texlive/2018/bin/x86_64-darwin'
我收到此错误:
kpathsea:make_tex:无效的文件名'DejaVu Serif',包含'' /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/init.py:886:MatplotlibDeprecation警告: examples.directory已弃用;将来,将找到与“ datapath”目录相关的示例。 “相对于'datapath'目录找到。”。format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/init.py:886:MatplotlibDeprecation警告: examples.directory已弃用;将来,将找到与“ datapath”目录相关的示例。 “相对于'datapath'目录找到。”。format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/init.py:886:MatplotlibDeprecation警告: examples.directory已弃用;将来,将找到与“ datapath”目录相关的示例。 “相对于'datapath'目录找到。”。format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/init.py:886:MatplotlibDeprecation警告: examples.directory已弃用;将来,将找到与“ datapath”目录相关的示例。 “相对于'datapath'目录找到。”。format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/init.py:886:MatplotlibDeprecation警告: examples.directory已弃用;将来,将找到与“ datapath”目录相关的示例。 “相对于'datapath'目录找到。”。format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/init.py:886:MatplotlibDeprecation警告: examples.directory已弃用;将来,将找到与“ datapath”目录相关的示例。 “相对于'datapath'目录找到。”。format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/init.py:886:MatplotlibDeprecation警告: examples.directory已弃用;将来,将找到与“ datapath”目录相关的示例。 “相对于'datapath'目录找到。”。format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/init.py:886:MatplotlibDeprecation警告: examples.directory已弃用;将来,将找到与“ datapath”目录相关的示例。 “相对于'datapath'目录找到。”。format(key)) /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/init.py:886:MatplotlibDeprecation警告: examples.directory已弃用;将来,将找到与“ datapath”目录相关的示例。 “相对于'datapath'目录找到。”。format(key)) 追溯(最近一次通话): 文件“ /Users/Marten/Downloads/pgf_preamble_sgskip.py”,第33行,在 plt.tight_layout(.5) 文件“ /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/pyplot.py”,行1382,在tight_layout中 gcf()。tight_layout(pad = pad,h_pad = h_pad,w_pad = w_pad,rect = rect) 文件“ /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/figure.py”,第2370行,在tight_layout中 渲染器= get_renderer(自己) 在get_renderer中的第228行,文件“ /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/tight_layout.py” 渲染器= canvas.get_renderer() 在get_renderer中的第946行,文件“ /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/backends/backend_pgf.py” 返回RendererPgf(self.figure,None,dummy = True) init 中的文件“ /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/backends/backend_pgf.py”,第393行 self.latexManager = LatexManagerFactory.get_latex_manager() 在get_latex_manager中的第208行,文件“ /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/backends/backend_pgf.py” new_inst = LatexManager() init 中的文件“ /Users/Marten/Library/Python/3.7/lib/python/site-packages/matplotlib/backends/backend_pgf.py”,第290行 “或序言中的错误:\ n%s”%stdout) matplotlib.backends.backend_pgf.LatexError:LaTeX返回了一个错误,可能是缺少字体或序言中的错误: b'这是XeTeX,版本3.14159265-2.6-0.99999(TeX Live 2018)(预加载格式= xelatex)\ n受限制的\ write18启用。\ n **进入扩展模式\ nLaTeX2e <2018-04-01>补丁程序级别2 \ \ n \ n *(/usr/local/texlive/2018/texmf-dist/tex/latex/base/minimal.cls\nDocument类别:最小2001 / 05/25标准LaTeX最小类\ n)\ n *(/ usr / local / texlive / 2018 / texmf-dist / tex / latex / units / units.sty \ n(/ usr / local / texlive / 2018 / texmf- dist / tex / latex / base / ifthen.sty)\ n(/usr/local/texlive/2018/texmf-dist/tex/latex/units/nicefrac.sty))\ n *(/ usr / local / texlive / 2018 / texmf-dist / tex / latex / metalogo / metalogo.sty \ n(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/graphicx.sty\n(/ usr / local / texlive / 2018 / texmf-dist / tex / latex / graphics / keyval.sty)\ n(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics/graphics.sty\n \ /(/ usr / local / texlive /2018/texmf-dist/tex/latex/graphics/trig.sty)\n(/usr/local/texlive/2018/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)\n(/ usr / local / texlive / 2018 / texmf-dist / tex / latex / graphics-def / xetex.def)))\ n(/ usr / local / texlive / 2018 / texmf-dist / tex / generic / ifxetex / ifxetex。 sty)\ n(/usr/local/texlive/2018/texmf-dist/tex/latex/fontspec/fontspec.sty\n(/ usr / local / texlive / 2018 / texmf-dist / tex / latex / l3packages / xparse /xparse.sty\n(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/expl3.sty\n(//usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel /expl3-code.tex)\n(/usr/local/texlive/2018/texmf-dist/tex/latex/l3kernel/l3xdvipdfmx.def)))\n(/usr/local/texlive/2018/texmf-dist /tex/latex/fontspec/fontspec-xetex.sty\n(/usr/local/texlive/2018/texmf-dist/tex/latex/base/fontenc.sty\n\/(/usr/local/texlive/2018/texmf -dist / tex / latex / base / tuenc.def))\ n(/usr/local/texlive/2018/texmf-dist/tex/latex/fontspec/fontspec.cfg)))))\ n *(/ usr /本地/texlive/2018/texmf-dist/tex/latex/unicode-math/unicode-math.sty\n(/usr/local/texlive/2018/texmf-dist/tex/latex/unicode-math/unicode-math -xetex.s \ nty \ n(/ usr / local / texlive / 2018 / texmf-dist / tex / latex / l3packages / l3key s2e / l3keys2e.sty)\ n(/usr/local/texlive/2018/texmf-dist/tex/latex/filehook/filehook.sty)\n(/usr/local/texlive/2018/texmf-dist/tex/ latex / base / fix-cm.sty \ n(/usr/local/texlive/2018/texmf-dist/tex/latex/base/ts1enc.def))\ n(/ usr / local / texlive / 2018 / texmf- dist / tex / latex / unicode-math / unicode-math-table.t \ nex)))\ n * \ n !!!!!!!!!!!!!!!!!!!!!!! \ n!\ n!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \ n!\ n! fontspec错误:“找不到字体” \ n! \ n!找不到字体“ DejaVu Serif”。\ n! \ n!有关更多信息,请参见fontspec文档。\ n! \ n!如需即时帮助,请键入H。\ n!..................................................... ...... \ n \ n <*> \ setmainfont {DejaVu Serif} \ n \ n没有输出页面。\ n在texput.log上编写的文字记录。\ n'
import matplotlib as mpl
mpl.use("pgf")
import matplotlib.pyplot as plt
import os
os.environ["PATH"] += os.pathsep + '/usr/local/texlive/2018/bin/x86_64-darwin'
plt.rcParams.update({
"font.family": "serif", # use serif/main font for text elements
"text.usetex": True, # use inline math for ticks
"pgf.rcfonts": False, # don't setup fonts from rc parameters
"pgf.texsystem" : "xelatex",
"pgf.preamble": [
"\\usepackage{units}", # load additional packages
"\\usepackage{metalogo}",
"\\usepackage{unicode-math}", # unicode math setup
r"\setmathfont{xits-math.otf}",
r"\setmainfont{DejaVu Serif}", # serif font via preamble
]
})
plt.figure(figsize=(4.5, 2.5))
plt.plot(range(5))
plt.xlabel("unicode text: я, ψ, €, ü, \\unitfrac[10]{°}{µm}")
plt.ylabel("\\XeLaTeX")
plt.legend(["unicode math: $λ=∑_i^∞ μ_i^2$"])
plt.tight_layout(.5)
plt.savefig("pgf_preamble.pdf")
plt.savefig("pgf_preamble.png")
答案 0 :(得分:0)
因此,我尝试了plt.rc('text', usetex=True)
和plt.rc('font', family='serif')
的另一种测试程序,没有多余的前言。当我添加路径os.environ["PATH"] += os.pathsep + '/usr/local/texlive/2018/bin/x86_64-darwin'
时,该方法有效。因此问题以不同的方式解决。 – madden994刚刚编辑