gpt4 book ai didi

Python:无法在 Matplotlib 中渲染 Tex

转载 作者:IT老高 更新时间:2023-10-28 21:51:01 28 4
gpt4 key购买 nike

我最近将笔记本电脑升级到 Snow Leopard,将 TeX 更新到版本 3.1415926 (TeX Live 2011/MacPorts 2011_5),并安装了 Python 2.7.3。在所有这些安装之后,我运行 macport selfupdate 和 macport upgrade outdated。但是,现在当我尝试在 matplotlib 中使用 TeX 时,我收到以下信息:

LaTeX was not able to process the following string:'lp'
Here is the full report generated by LaTeX:

This is pdfTeX, Version 3.1415926-2.3-1.40.12 (TeX Live 2011/MacPorts 2011_5)
restricted \write18 enabled.
entering extended mode (./64a53cc27244d5ee10969789771e33fa.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, dumylang, nohyphenation, cz
ech, slovak, dutch, ukenglish, usenglishmax, basque, french, german-x-2009-06-1
9, ngerman-x-2009-06-19, german, ngerman, swissgerman, italian, polish, portugu
ese, spanish, catalan, galician, ukenglish, loaded.
(/opt/local/share/texmf-texlive-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/opt/local/share/texmf-texlive-dist/tex/latex/base/size10.clo))

! LaTeX Error: File `type1cm.sty' not found.

Type X to quit or <RETURN> to proceed, or enter new name. (Default extension: sty)


l.3 \renewcommand
{\rmdefault}{pnc}^^M
No pages of output.

类似于 this previous question ,我尝试通过以下方式在我的python代码中设置路径:

os.environ['PATH'] = os.environ['PATH'] + ':/opt/local/bin/latex'

因为 which latex 产生了 /opt/local/bin/latex。但是,这不起作用,并显示相同的错误消息。我还尝试了 tex 的路径,以及上一个问题中的示例。没有变化。

然后我尝试通过以下方式强制可能丢失的包:

matplotlib.rcParams['text.latex.preamble']=[r"\usepackage{amsmath}"]

但是,这也不起作用。

我可以让我的绘图工作的唯一方法是说 rc('text', usetex=False),这并不理想。任何帮助将不胜感激。

最佳答案

在 Ubunutu 14.04 机器上,上述答案的组合有效。我 sudo apt-get install dvipngtexlive-latex-extratexlive-fonts-recommended 包这就是诀窍:

$ sudo apt-get install dvipng texlive-latex-extra texlive-fonts-recommended 

编辑:从 Matplotlib 3.2.1 开始,您现在还需要包 cm-super(见 https://github.com/matplotlib/matplotlib/issues/16911)

$ sudo apt-get install dvipng texlive-latex-extra texlive-fonts-recommended cm-super

关于Python:无法在 Matplotlib 中渲染 Tex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11354149/

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