使用pythontex将matplotlib图形嵌入乳胶文档
pythontexfigures的Python项目详细描述
乳胶Python图
给定一个像这样绘制matplotlib图的python脚本:
defmain():x=np.arange(10)y=x**2plt.plot(x,y)plt.xlabel('$x$')plt.ylabel('$x^2$')return'test'# Figure filename
您可以将其插入这样的乳胶文档:
\begin{figure}\pyfig{'test.py'}\caption{Test figure.}\end{figure}
默认情况下,图形大小默认为\textwidth
正方形,字体和字体大小与文档的其余部分匹配。
安装
需要安装Latex(可能是Tex Live 2019)、Pythontex和Python3.6或更高版本。
示例需要latexmk。
要安装python包:
pip3 install pythontexfigures
要将乳胶包安装到texmf-local
:
sudo python3 -m pythontexfigures.install
如果您没有根访问权限,可以将其安装到texmf-home
中,而不是:
sudo python3 -m pythontexfigures.install TEXMFHOME
或者,在pythontexcustomcode中调用pf.print_preamble()
,然后使用\printpythontex
。