Save multiple plots in a single PDF file
matplotlib, python
Solution
Never mind got the way to do 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 -----
Problem
plotting module ``` def plotGraph(X,Y): fignum = random.randint(0,sys.maxint) plt.figure(fignum) ### Plotting arrangements ### return fignum ``` main module ``` 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() ``` 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. 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?