I have a for loop for plotting a set of figures and I would like to have ONE pdf as an outcome with all these figures. I am using plt.show()
but I am not sure where to put the fig.savefig('file_name.pdf')
or how to do it in different way. Right now it just gives me the last figure.
My code:
dpi = 100
margin = 0.05
xpixels, ypixels = 300, 600
for i in range(1,17):
chr = pd.read_csv("chr"+str(i)+".txt", sep="\s+", header=None)
print(chr.shape)
figsize = (1 + margin) * ypixels / dpi, (1 + margin) * xpixels / dpi
fig = plt.figure(figsize = figsize, dpi = dpi)
ax = fig.add_axes([margin, margin, 1 - 2*margin, 1 - 2*margin])
plt.ylabel("individuals")
plt.title("Chromosome "+ str(i))
ax.imshow(chr.values, interpolation='nearest', aspect = 4, cmap = plt.get_cmap('winter'))
plt.show()
fig.savefig('file_name.pdf')
Thank you for any ideas. :)