Python:无法在 Matplotlib 中渲染 Tex [英] Python: Unable to Render Tex in Matplotlib

查看:37
本文介绍了Python:无法在 Matplotlib 中渲染 Tex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I recently upgraded my laptop to Snow Leopard, updated TeX to Version 3.1415926 (TeX Live 2011/MacPorts 2011_5), and installed Python 2.7.3. After all these installs, I ran macport selfupdate and macport upgrade outdated. However, now when I try to use TeX in matplotlib, I receive the following:

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 
enewcommand
             {
mdefault}{pnc}^^M
No pages of output.

类似于上一个问题,我尝试通过以下方式在我的 python 代码中设置路径:

Similar to this previous question, I tried setting the path in my python code via:

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

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

since which latex yielded /opt/local/bin/latex. However, that didn't work, with the same error message. I also tried the path to tex, as well as the example from the previous question. No change.

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

I then tried to force possibly missing packages via:

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

然而,这也不起作用.

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

The only way I can get my plots to work is to say rc('text', usetex=False), which is not ideal. Any help would be much appreciated.

推荐答案

错误消息说您缺少 type1cm 包.MacPorts 似乎将它作为 texlive-latex-extra 的一部分包含在内.

The error message says you're missing the type1cm package. It seems that MacPorts includes it as part of texlive-latex-extra.

这篇关于Python:无法在 Matplotlib 中渲染 Tex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆