def save_images(dir='', figs=None, prefix=None): """ Save all open figures to image files. Parameters: ---------- dir : string Directory to place image files into figs : list of Figures will default to open figures prefix : string prefix all image file names """ if figs is None: figs = pylabtools.getfigs() if dir: mkdir_p(dir) for i, fig in enumerate(figs, 1): label = _get_title(fig) if label == '': label = "Figure_%d" % i if prefix: label = prefix + '_' + label filepath = os.path.join(dir, label+'.png') fig.savefig(filepath) close_figures()
def embed(): """Simple method for embedding all current figures in the current ipython notebook cell. Use at the end of a cell. Only works when the ipython notebook has been started with '--pylab' (note: NOT '--pylab=inline')""" # getfigs = pylabtools.getfigs display.display(*pylabtools.getfigs()) plt.close('all')
def save_to_pdf(file, figs=None): with PdfPages(file) as pdf: if figs is None: figs = pylabtools.getfigs() for fig in figs: fig.savefig(pdf, format='pdf') close_figures()
def save_to_pdf(file, figs=None): pp = PdfPages(file) if figs is None: figs = pylabtools.getfigs() for fig in figs: fig.savefig(pp, format='pdf') pp.close() close_figures()
def embed(): """Simple method for embedding all current figures in the current ipython notebook cell. Use at the end of a cell. Only works when the ipython notebook has been started with '--pylab' (note: NOT '--pylab=inline') NOTE: DEPRECATED!! Start ipython notebook with `ipython notebook` and include `%matplotlib inline` in the top cell instead! """ display.display(*pylabtools.getfigs()) plt.close('all')