设置样式表后如何恢复Matplotlib默认值 [英] How to recover matplotlib defaults after setting stylesheet
问题描述
在ipython笔记本中,我使用matplotlib样式表使用
In an ipython notebook, I used a matplotlib stylesheet to change the look of my plots using
from matplotlib.pyplot import *
%matplotlib inline
style.use('ggplot')
我的matplotlib版本是1.4.0.如何返回默认的matplotlib样式?我尝试了所有可用的样式
My version of matplotlib is 1.4.0. How do I go back to the default matplotlib styling? I tried all the available styles in
print style.available
,但似乎没有默认"选项.我也尝试过
but there doesn't seem to be a "default" option. I also tried
matplotlib.rcdefaults()
由于某种原因,这给了我灰色背景.还将文本从灰色(ggplot样式)更改为黑色,这可能是默认样式,但也可能是另一种随机样式.
For some reason, this gives me a gray background. It also changes the text from gray (ggplot style) to black, which may be the default, but also could be another random style.
推荐答案
您应该能够通过以下方式将其设置为默认值:
You should be able to set it back to default by:
import matplotlib as mpl
mpl.rcParams.update(mpl.rcParamsDefault)
在ipython
中,情况有所不同,尤其是对于inline
后端:
In ipython
, things are a little different, especially with inline
backend:
In [1]:
%matplotlib inline
In [2]:
import matplotlib as mpl
import matplotlib.pyplot as plt
In [3]:
inline_rc = dict(mpl.rcParams)
In [4]:
plt.plot(range(10))
Out[4]:
[<matplotlib.lines.Line2D at 0x72d2510>]
In [5]:
mpl.rcParams.update(mpl.rcParamsDefault)
plt.plot(range(10))
Out[5]:
[<matplotlib.lines.Line2D at 0x7354730>]
In [6]:
mpl.rcParams.update(inline_rc)
plt.plot(range(10))
Out[6]:
[<matplotlib.lines.Line2D at 0x75a8e10>]
基本上,%matplotlib inline
使用其自己的rcParams
.您可以从源头上获取它,但是可以争论的更简单的方法可能是在此示例中,将rcParams
另存为inline_rc
在%matplotlib inline
细胞魔术之后,然后再使用.
Basically, %matplotlib inline
uses its own rcParams
. You can grab that from the source, but the arguably easier way is probably just save the rcParams
as inline_rc
after %matplotlib inline
cell magic in this example, and reuse that later.
这篇关于设置样式表后如何恢复Matplotlib默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!