set_plot_params.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:matplotlib_pubplots 作者: yoachim 项目源码 文件源码
def plot_multi_format(plot_funcs, plot_kwargs=None,
                      usetex=False, outdir='plots',
                      setting_funcs=['single', 'span', 'slides', 'thumbnails']):
    """
    Outputs plots formatted 4 ways: Publication ready (narrow and wide),
    PowerPoint ready, and png thumbnails.

    input
    -----
    plot_funcs : List of functions that return a mpl figure and a filename (or list of figures and filenames)

    """

    setting_dict = {'single': mpl_single_column,
                    'span': mpl_span_columns,
                    'slides': mpl_slides,
                    'thumbnails': mpl_thumbnails}

    if not os.path.exists(outdir):
        os.makedirs(outdir)
    # For python 3.4
    # os.makedirs(outdir, exist_ok=True)

    if plot_kwargs is None:
        plot_kwargs=[{}]*len(plot_funcs)

    for key in setting_funcs:
        setting_dict[key](usetex=usetex)
        for plot_func,pkwargs in zip(plot_funcs,plot_kwargs):
            figs, names = plot_func(**pkwargs)
            for fig,name in zip(figs,names):
                fig.savefig(os.path.join(outdir, key+'_'+name))
            plt.close('all')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号