83

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')

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() 

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.

amd
  • 1,697
  • 2
  • 13
  • 19

3 Answers3

107

You should be able to set it back to default by:

import matplotlib as mpl
mpl.rcParams.update(mpl.rcParamsDefault)

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>]

enter image description here

In [5]:

mpl.rcParams.update(mpl.rcParamsDefault)
plt.plot(range(10))
Out[5]:
[<matplotlib.lines.Line2D at 0x7354730>]

enter image description here

In [6]:

mpl.rcParams.update(inline_rc)
plt.plot(range(10))
Out[6]:
[<matplotlib.lines.Line2D at 0x75a8e10>] 

enter image description here

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.

CT Zhu
  • 52,648
  • 17
  • 120
  • 133
  • That gives me the same thing as when I tried matplotlib.rcdefaults(). Does setting the stylesheet change the default parameters? – amd Oct 16 '14 at 21:18
  • Are you using `ipython` `%matplotlib inline`? – CT Zhu Oct 16 '14 at 21:21
  • Yes, I'm using `ipython %matplotlib inline` – amd Oct 16 '14 at 22:09
  • Actually, I'm using `ipython notebook` with `%matplotlib inline` - in case that makes a difference – amd Oct 16 '14 at 22:10
  • Yep, that makes a lot of difference. `inline` cell magic uses a different `rcParams` – CT Zhu Oct 16 '14 at 22:41
  • Getting this:'The examples.directory rcparam was deprecated in Matplotlib 3.0 and will be removed in 3.2. In the future, examples will be found relative to the 'datapath' directory.' – multitudes Feb 25 '20 at 09:55
  • Strangely enough, figure size still doesn't get reset with this method. – huggie Dec 11 '22 at 15:48
53

There actually is a default. But it's not listed under plt.style.available. Simply run :

plt.style.use('default')

It returns the style to the default Matplotlib settings in, for instance, Jupyter Notebook.

user4157124
  • 2,809
  • 13
  • 27
  • 42
dequation
  • 531
  • 5
  • 4
2

Adding to the answer by CT Zhu, the differences between the inline and matplotlib defaults are (for each item that is different, a list with the to respective values is given):

inline_default_rc = dict(mpl.rcParams)
default_rc = dict(mpl.rcParamsDefault)
print( {k:[v,default_rc[k]] for k,v in inline_default_rc.items() if v != default_rc[k]} )

{'figure.dpi': [72.0, 100.0], 'figure.edgecolor': [(1, 1, 1, 0), 'white'], 'figure.facecolor': [(1, 1, 1, 0), 'white'], 'figure.figsize': [[6.0, 4.0], [6.4, 4.8]], 'figure.subplot.bottom': [0.125, 0.11], 'interactive': [True, False]}

You can use this to fine tune your plots.