将地块保存为PDF [英] Save the plots into a PDF
本文介绍了将地块保存为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.
有一个名为pylab.savefig
的函数,但只有将其与绘图模块一起放置时,该函数才起作用.还有其他方法可以实现吗?
There's a function named pylab.savefig
but that seems to work only if it's placed along with plotting module. 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 ----
----- 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屋!
查看全文