(fullpath, code, outdir)
return len(fig_managers)
run a pyplot script and save the low and high res PNGs and a PDF in _static
run a pyplot script and save the low and high res PNGs and a PDF in _static
run a pyplot script and save the low and high res PNGs and a PDF in _static
def makefig(fullpath, code, outdir):
    """
    run a pyplot script and save the low and high res PNGs and a PDF in _static
    """
    formats = [('png', 80), ('hires.png', 200), ('pdf', 50)]

    fullpath = str(fullpath)  # todo, why is unicode breaking this
    basedir, fname = os.path.split(fullpath)
    basename, ext = os.path.splitext(fname)

    if str(basename) == "None":
        import pdb
        pdb.set_trace()

    all_exists = True

    # Look for single-figure output files first
    for format, dpi in formats:
        outname = os.path.join(outdir, '%s.%s' % (basename, format))
        if out_of_date(fullpath, outname):
            all_exists = False
            break

    if all_exists:
        write_char('.' * len(formats))
        return 1

    # Then look for multi-figure output files, assuming
    # if we have some we have all...
    i = 0
    while True:
        all_exists = True
        for format, dpi in formats:
            outname = os.path.join(outdir, '%s_%02d.%s' % (basename, i, format))
            if out_of_date(fullpath, outname):
                all_exists = False
                break
        if all_exists:
            i += 1
        else:
            break

    if i != 0:
        write_char('.' * i * len(formats))
        return i

    # We didn't find the files, so build them

    plt.close('all')    # we need to clear between runs
    matplotlib.rcdefaults()
    # Set a figure size that doesn't overflow typical browser windows
    matplotlib.rcParams['figure.figsize'] = (5.5, 4.5)

    if code is not None:
        exec(code)
    else:
        try:
            runfile(fullpath)
        except:
            traceback.print_exc()
            s = ("Exception running plot %s" % fullpath)
            warnings.warn(s)
            return 0

    fig_managers = _pylab_helpers.Gcf.get_all_fig_managers()
    for i, figman in enumerate(fig_managers):
        for format, dpi in formats:
            if len(fig_managers) == 1:
                outname = basename
            else:
                outname = "%s_%02d" % (basename, i)
            outpath = os.path.join(outdir, '%s.%s' % (outname, format))
            try:
                figman.canvas.figure.savefig(outpath, dpi=dpi)
            except:
                s = cbook.exception_to_str("Exception running plot %s" % fullpath)
                warnings.warn(s)
                return 0

            write_char('*')

    return len(fig_managers)
def makefig ( fullpath , code , outdir ) : formats = [ ( 'png' , 80 ) , ( 'hires.png' , 200 ) , ( 'pdf' , 50 ) ] fullpath = str ( fullpath ) # todo, why is unicode breaking this basedir , fname = os . path . split ( fullpath ) basename , ext = os . path . splitext ( fname ) if str ( basename ) == "None" : import pdb pdb . set_trace ( ) all_exists = True # Look for single-figure output files first for format , dpi in formats : outname = os . path . join ( outdir , '%s.%s' % ( basename , format ) ) if out_of_date ( fullpath , outname ) : all_exists = False break if all_exists : write_char ( '.' * len ( formats ) ) return 1 # Then look for multi-figure output files, assuming # if we have some we have all... i = 0 while True : all_exists = True for format , dpi in formats : outname = os . path . join ( outdir , '%s_%02d.%s' % ( basename , i , format ) ) if out_of_date ( fullpath , outname ) : all_exists = False break if all_exists : i += 1 else : break if i != 0 : write_char ( '.' * i * len ( formats ) ) return i # We didn't find the files, so build them plt . close ( 'all' ) # we need to clear between runs matplotlib . rcdefaults ( ) # Set a figure size that doesn't overflow typical browser windows matplotlib . rcParams [ 'figure.figsize' ] = ( 5.5 , 4.5 ) if code is not None : exec ( code ) else : try : runfile ( fullpath ) except : traceback . print_exc ( ) s = ( "Exception running plot %s" % fullpath ) warnings . warn ( s ) return 0 fig_managers = _pylab_helpers . Gcf . get_all_fig_managers ( ) for i , figman in enumerate ( fig_managers ) : for format , dpi in formats : if len ( fig_managers ) == 1 : outname = basename else : outname = "%s_%02d" % ( basename , i ) outpath = os . path . join ( outdir , '%s.%s' % ( outname , format ) ) try : figman . canvas . figure . savefig ( outpath , dpi = dpi ) except : s = cbook . exception_to_str ( "Exception running plot %s" % fullpath ) warnings . warn ( s ) return 0 write_char ( '*' ) return len ( fig_managers )