def plot2pdf(title='new_plot', fig=None, rasterized=True, dpi=160,\ justHH=False, no_dstr=True, save2png=True, \ save2eps=False, transparent=True, debug=False ): """ Save figures (e.g. matplotlib) to pdf file """ # set save directory ( using default directory dictionary ) from funcs_vars import get_dir wd = get_dir('ppwd') # Set pdf name if justHH: date_str = time.strftime("%y_%m_%d_%H") else: date_str = time.strftime("%y_%m_%d_%H_%M") if no_dstr: npdf = wd+title else: npdf = wd+date_str+'_'+title # setup pdf pdf = PdfPages(npdf +'.pdf' ) # Rasterise to save space? if rasterized: plt.gcf().set_rasterized(True) # save and close type = 'PDF' pdf.savefig( dpi=dpi, transparent=transparent ) pdf.close() # Also export to png and eps? if save2png: type += '/PDF' plt.savefig(npdf+'.png', format='png', dpi=dpi, \ transparent=transparent ) if save2eps: type += '/EPS' plt.savefig(npdf+'.eps', format='eps', dpi=dpi, \ transparent=transparent) print type+' saved & Closed as/at: ', npdf
def plot2pdf(title='new_plot', fig=None, rasterized=True, dpi=160,\ justHH=False, no_dstr=True, save2png=True, \ save2eps=False, transparent=True, debug=False ): """ Save figures (e.g. matplotlib) to pdf file """ # set save directory ( using default directory dictionary ) from funcs_vars import get_dir wd = get_dir('ppwd') # Set pdf name if justHH: date_str = time.strftime("%y_%m_%d_%H") else: date_str = time.strftime("%y_%m_%d_%H_%M") if no_dstr: npdf = wd + title else: npdf = wd + date_str + '_' + title # setup pdf pdf = PdfPages(npdf + '.pdf') # Rasterise to save space? if rasterized: plt.gcf().set_rasterized(True) # save and close type = 'PDF' pdf.savefig(dpi=dpi, transparent=transparent) pdf.close() # Also export to png and eps? if save2png: type += '/PDF' plt.savefig(npdf+'.png', format='png', dpi=dpi, \ transparent=transparent ) if save2eps: type += '/EPS' plt.savefig(npdf+'.eps', format='eps', dpi=dpi, \ transparent=transparent) print type + ' saved & Closed as/at: ', npdf
def plot2pdfmulti(pdf=None, title='new_plot', rasterized=True, \ dpi=160, open=False, close=False, justHH=False, no_dstr=False ): """ Save figures (e.g. matplotlib) to pdf file with multiple pages """ # set save directory ( using default directory dictionary ) from funcs4core import get_dir wd = get_dir('ppwd') # Set pdf name if justHH and (not no_dstr): date_str = time.strftime("%y_%m_%d_%H") if not no_dstr: date_str = time.strftime("%y_%m_%d_%H_%M") if no_dstr: npdf = wd+title+'.pdf' else: npdf = wd+date_str+'_'+title+'.pdf' # If 1st call ( open ==True), setup pdf if open: pdf = PdfPages(npdf) print 'pdf opened @: {}'.format( npdf ) return pdf # Rasterise to save space? if rasterized: plt.gcf().set_rasterized(True) # save and close or keep open to allow additions of plots if close: pdf.close() print 'PDF saved & Closed as/at: ', npdf else: pdf.savefig(dpi=dpi) print 'pdf is still open @: {}'.format( npdf )
def plot2pdfmulti(pdf=None, title='new_plot', rasterized=True, \ dpi=160, open=False, close=False, justHH=False, no_dstr=False ): """ Save figures (e.g. matplotlib) to pdf file with multiple pages """ # set save directory ( using default directory dictionary ) from funcs_vars import get_dir # Kludge wd = get_dir('ppwd') # Set pdf name if justHH and (not no_dstr): date_str = time.strftime("%y_%m_%d_%H") if not no_dstr: date_str = time.strftime("%y_%m_%d_%H_%M") if no_dstr: npdf = wd + title + '.pdf' else: npdf = wd + date_str + '_' + title + '.pdf' # If 1st call ( open ==True), setup pdf if open: pdf = PdfPages(npdf) print 'pdf opened @: {}'.format(npdf) return pdf # Rasterise to save space? if rasterized: plt.gcf().set_rasterized(True) # save and close or keep open to allow additions of plots if close: pdf.close() print 'PDF saved & Closed as/at: ', npdf else: pdf.savefig(dpi=dpi) print 'pdf is still open @: {}'.format(npdf)