matplotlib.pyplot.rc_context#

matplotlib.pyplot.rc_context(rc=None, fname=None)[源代码][源代码]#

返回一个用于临时更改 rcParams 的上下文管理器。

上下文管理器不会重置 rcParams["后端"]

通过上下文管理器调用和在上下文主体中更改的 rcParams 将在上下文退出时重置。

参数:
rcdict

要临时设置的 rcParams。

fnamestr 或 path-like

一个包含 Matplotlib rc 设置的文件。如果同时给出了 fnamerc,则 rc 中的设置优先。

参见

使用matplotlibrc文件自定义

注释

备注

这等同于 matplotlib.rc_context

示例

通过字典传递显式值:

with mpl.rc_context({'interactive': False}):
    fig, ax = plt.subplots()
    ax.plot(range(3), range(3))
    fig.savefig('example.png')
    plt.close(fig)

从文件加载设置:

with mpl.rc_context(fname='print.rc'):
    plt.plot(x, y)  # uses 'print.rc'

在上下文主体中设置:

with mpl.rc_context():
    # will be reset
    mpl.rcParams['lines.linewidth'] = 5
    plt.plot(x, y)

使用 matplotlib.pyplot.rc_context 的示例#

样式表引用

Style sheets reference

Matplotlib 标志

Matplotlib logo