使用`with`恢复Matplotlib默认样式

问题描述

我希望能够使用惯用法为Matplotlib图临时使用任意钉书钉

with my_styles(style):
    # plotting code ...

并已定义

def my_styles(style='mine'):
    if style == 'mine':
        return plt.rc_context({
            "font.family": "sans-serif","mathtext.fontset": "dejavusans","font.sans-serif": ["Nunito","Open Sans"] + plt.rcParams["font.sans-serif"],"text.usetex": False })
    elif style == 'another': 
        # USE - Very slow (?)
        return plt.rc_context({
            'axes.linewidth': 1.5,'lines.linewidth': 2.0,'figure.facecolor': 'white','grid.linewidth': 0.0,'axes.grid': False,'axes.unicode_minus': False,'axes.edgecolor': 'black','text.usetex': True
        })
    else:
        return plt.rc_context(plt.rc_params())

但是最后一种情况不会恢复Matplotlib的认样式,而是继续使用以前使用的样式。如何完全还原Matplotlib的认值,以及使用rc_contextwith进行此操作的正确习惯是什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)