matplotlib - 使用 `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_context
and这样做的正确习惯是什么with
?
解决方案
推荐阅读
- android - webview权限android pie
- c# - 如何在 C# 中迭代时从嵌套列表中删除所有项目
- android - 网站无法识别保存在 Smartlock 中的凭据
- amazon-ec2 - 如何创建可以休眠的 ec2 实例?
- python - __invert__ 方法
- c# - 标签属性上的 WPF MultiDataTrigger 仅触发一次
- c# - 使用自定义 dll 时 SISS 包损坏
- javascript - 逗号分隔、冒号或破折号分隔值的 MAC 地址正则表达式验证
- google-chrome - Joomla 页面有多少级缓存
- r - 重新采样/聚合 NetCDF 文件以解析第二个 NetCDF 文件