在Inkscape中,可以勾选保存并将扩展名指定为
我想直接从我的Python脚本中保存Matplotlib图形到这种特定的格式中。是否存在这种可能性或者有什么技巧可以做到呢?
.pdf
,同时生成pdf_tex文件以便自动格式化成Latex文件。我想直接从我的Python脚本中保存Matplotlib图形到这种特定的格式中。是否存在这种可能性或者有什么技巧可以做到呢?
.pdf
,同时生成pdf_tex文件以便自动格式化成Latex文件。import matplotlib.pyplot as plt
plt.bar(x=[1,2], height=[3,4], label="Bar")
plt.legend()
plt.xlabel("Label")
plt.title("title")
def savepdf_tex(fig, name, **kwargs):
import subprocess, os
fig.savefig("temp.pdf", format="pdf", **kwargs)
incmd = ["inkscape", "temp.pdf", "--export-pdf={}.pdf".format(name),
"--export-latex"] #"--export-ignore-filters",
subprocess.check_output(incmd)
os.remove("temp.pdf")
savepdf_tex(plt.gcf(), "latest")
plt.show()
pgf
格式。它绝对值得尝试作为上述方法的替代方案。请参见this example,并将plt.savefig("filename.pgf")
添加到其中。在latex代码中使用\input{filename.pgf}
。FileNotFoundError: [WinError 2] 系统找不到指定的文件
。 - undefined几年前,我创建了一个matplotlib后端,专门支持此功能。但是,它只与较旧版本的matplotlib兼容,需要更新(我将感激任何贡献)。
@ImportanceOfBeingErnest 已经提到过这个解决方案。但是,如果该解决方案失败,请尝试使用--export-filename
或-o
代替--export-pdf
。