我尝试了 G.Poore 的解决方案(https://github.com/gpoore/pythontex/wiki/matplotlib) 以便使用 Pythontex 轻松地在 TeX 文档中包含大量图形。
不幸的是,我收到以下错误并且无法修复它。
---- Messages for pylab:default:default ----
Traceback (most recent call last):
* PythonTeX stderr - error on line 18:
File "<outputdir>/pylab_default_default.py", line 69, in <module>
name = savefig()
File "/Users/.../python_preambule.py", line 17, in savefig
name = 'auto_fig_{}-{}'.format(pytex.id, fig_count)
NameError: name 'pytex' is not defined
平均能量密度 (MVE):
\documentclass[11pt]{article}
\usepackage{pythontex}
\begin{pythontexcustomcode}[begin]{pylab}
sys.path.append('/Users/.../preambulepython/')
from python_preamble import *
\end{pythontexcustomcode}
\begin{document}
\begin{pylabcode}
x = linspace(0, pi)
plt.plot(x, sin(x), label='sin(x)')
plt.plot(x, cos(x), label='cos(x)')
name = savefig()
fig = latex_figure(name)
\end{pylabcode}
\pylab{fig}
\end{document}