I've been fighting with pyplot for few days now. I want to return a pdf report with 4 samples on each page. 4 inline subplots for each: text with the name and some statistics, and 3 graphs of values vs time. I found a tutorial online and tried it (see below) but it gives nothing. the pdf is empty. I can't find where it is wrong. Thank you in advance !
from matplotlib.backends.backend_pdf import PdfPages
import matplotlib.pyplot as plt
t=[n*5 for n in range(len(ratio))]
y_list_ratio=[[x*100/l[3]for x in l[2]]for l in hit_ratio]
props = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
pp = PdfPages('multipage.pdf')
# Generate the pages
nb_plots = len(hit_ratio)
nb_plots_per_page = 4
nb_pages = int(numpy.ceil(nb_plots / float(nb_plots_per_page)))
grid_size = (nb_plots_per_page, 4)
for i, elt in enumerate(hit_ratio):
# Create a figure instance (ie. a new page) if needed
if i % nb_plots_per_page == 0:
plt = plt.figure(figsize=(8.27, 11.69), dpi=100)
# Plot stuffs !
plt.subplot2grid(grid_size, (i % nb_plots_per_page, 0))
plt.text(0.5,0.5,"Puit Hauteur_pic Digitonine\n"+ \
str(elt[-1])+" "+str(elt[5])+" "+str(elt[6]),horizontalalignment='center',verticalalignment='center', bbox=props)
plt.subplot2grid(grid_size, (i % nb_plots_per_page, 1))
plt.plot(t,hit_norm[i][0])
plt.subplot2grid(grid_size, (i % nb_plots_per_page, 2))
plt.plot(t,y_list_ratio[i])
plt.subplot2grid(grid_size, (i % nb_plots_per_page, 3))
plt.plot(t,elt[7])
plt.plot(t,elt[8])
# Close the page if needed
if (i + 1) % nb_plots_per_page == 0 or (i + 1) == nb_plots:
fig2.tight_layout()
pp.savefig(fig2)
# Write the PDF document to the disk
pp.close()