我正在使用乳胶在matplotlib中渲染文本,但是如果其中包含乳胶环境,则无法保存图形。
简化代码:
import matplotlib as mpl
mpl.use('PS')
import matplotlib.pyplot as plt
mpl.rcParams['text.usetex'] = True
s = (r"\begin{description}"
r"\item[someitem:] blah blah blah blah blah \\"
r"Some more text that I want to add to my plot"
r"\item[anotheritem:] This is even more text"
r"\end{description}")
plt.text(0,0,s)
plt.savefig('myfig.eps')
当我尝试保存它时,出现一般性乳胶错误。
!LaTeX错误:出了点问题-也许缺少\ item。
有关说明,请参阅LaTeX手册或LaTeX Companion。键入H以立即获得帮助。
但是,我认为我的乳胶没有任何问题。我尝试只在上面的代码片段中编译一个乳胶文档,并且效果很好。
有趣的是,如果我将交互式后端与ipython / jupyter-notebook一起使用,则该图将被渲染,但仍无法将图形另存为ps或eps文件。如果我删除了\begin{...} ... \end{...}
如果在文本中使用乳胶环境,如何将图形另存为ps / eps文件?
您必须处于垂直模式。您可以将文字换成parbox
:
import matplotlib as mpl
mpl.use('PS')
import matplotlib.pyplot as plt
mpl.rcParams['text.usetex'] = True
s = (r"\parbox{4in}{"
r"\begin{description}"
r"\item[someitem:] blah blah blah blah blah \\"
r"Some more text that I want to add to my plot"
r"\item[anotheritem:] This is even more text"
r"\end{description}"
r"}"
)
plt.text(0,0,s)
plt.savefig('myfig.eps')
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句