python - Multiple plots on pdf with matplotlib -


i've been fighting pyplot few days now. want return pdf report 4 samples on each page. 4 inline subplots each: text name , statistics, , 3 graphs of values vs time. found tutorial online , tried (see below) gives nothing. pdf empty. can't find wrong. thank in advance !

from matplotlib.backends.backend_pdf import pdfpages import matplotlib.pyplot plt  t=[n*5 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 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)  i, elt in enumerate(hit_ratio):   # create figure instance (ie. new page) if needed     if % 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 page if needed     if (i + 1) % nb_plots_per_page == 0 or (i + 1) == nb_plots:         fig2.tight_layout()         pp.savefig(fig2)  # write pdf document disk pp.close() 

since don't have answers yet, have alternate suggestion:

try reportlab.

from reportlab.lib import colors, utils reportlab.pdfgen import canvas reportlab.lib.pagesizes import letter, landscape reportlab.lib.units import inch reportlab.platypus import simpledoctemplate, table, tablestyle, image, pagebreak, keeptogether reportlab.lib.styles import paragraphstyle ps reportlab.lib.enums import ta_center reportlab.platypus.paragraph import paragraph  landscape_pic_width = 8 letter_pic_width = 6  ....  def get_image(path, width=1*inch): #'''returns image adding report'''     img = utils.imagereader(path)     iw, ih = img.getsize()     aspect = ih / float(iw)     return image(path, width=width, height=(width * aspect))  def plot_stuff():     #whatever want plot, finish saving figure  elements = [] #this list contain items included in report report_title = str(report_title)   c_table = table(conditions_table_data) c_table.setstyle(tablestyle([('align', (0,0),(-1,-1),'center'), ('innergrid', (0,0), (-1,-1), 0.25, colors.black), ('box', (0,0),(-1,-1), 2, colors.blueviolet), ('size', (0,0),(-1,-1), 10), ('span',(-3,3),(-1,3))])) #tells how format table   #puts in logo, assigned report title, entered report title, conditions table, , setup picture elements.append(get_image(logo_picture, width = 9*inch)) elements.append(paragraph(document_title, ps(name='heading1', spaceafter = 22, fontname = 'times-bold', fontsize = 18, alignment = ta_center)))   #you can append items list "elements" loop.   doc = simpledoctemplate(path_plus_title + ".pdf", pagesize=landscape(letter))  #creates report. throw error if report exists , open. otherwise, generate report  #this overwrite existing report same name. timestamps being forced data file names help.  doc.build(elements) 

there's sections missing code...but these items import ("inch", instance, value sizing multiply number of inches want dimension)

you build list of items go report pdf in order go in. each element, there's style setting takes place. can include text (paragraphs), tables (it's "list of lists" each list being row), , images.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -