将多个绘图保存在一个 PDF 文件中 [英] Save multiple plots in a single PDF file
本文介绍了将多个绘图保存在一个 PDF 文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
def plotGraph(X,Y):
fignum = random.randint(0,sys.maxint)
plt.figure(fignum)
### Plotting arrangements ###
return fignum
主模块
import matplotlib.pyplot as plt
### tempDLStats, tempDLlabels are the argument
plot1 = plotGraph(tempDLstats, tempDLlabels)
plot2 = plotGraph(tempDLstats_1, tempDLlabels_1)
plot3 = plotGraph(tempDLstats_2, tempDLlabels_2)
plt.show()
我想将所有图形 plot1、plot2、plot3 保存到一个 PDF 文件中.有什么方法可以实现吗?我无法在主模块中包含 plotGraph
函数.
I want to save all the graphs plot1, plot2, plot3 to a single PDF file. Is there any way to achieve it? I can't include the plotGraph
function in the main module.
有一个名为 pyplot.savefig
的函数,但它似乎只适用于单个图形.还有其他方法可以实现吗?
There's a function named pyplot.savefig
but that seems to work only with a single figure. Is there any other way to accomplish it?
推荐答案
没关系有办法去做.
def plotGraph(X,Y):
fignum = random.randint(0,sys.maxint)
fig = plt.figure(fignum)
### Plotting arrangements ###
return fig
------绘图模块------
------ plotting module ------
----- 主模块 ----
----- mainModule ----
import matplotlib.pyplot as plt
### tempDLStats, tempDLlabels are the argument
plot1 = plotGraph(tempDLstats, tempDLlabels)
plot2 = plotGraph(tempDLstats_1, tempDLlabels_1)
plot3 = plotGraph(tempDLstats_2, tempDLlabels_2)
plt.show()
plot1.savefig('plot1.png')
plot2.savefig('plot2.png')
plot3.savefig('plot3.png')
----- mainModule -----
----- mainModule -----
这篇关于将多个绘图保存在一个 PDF 文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文