Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recover matplotlib defaults after setting stylesheet

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.

like image 895
amd Avatar asked Oct 16 '14 20:10

amd


People also ask

How do I reset matplotlib rcParams?

Use matplotlib. style. use('default') or rcdefaults() to restore the default rcParams after changes.

How do I set the default style in matplotlib?

plt. style. use('default') worked for me. As I understand this, it tells matplotlib to switch back to its default style mode.

What is the default backend for matplotlib?

In modern matplotlib there is no "default backend", i.e. the rcParams['backend'] is set to a "sentinel". Upon importing matplotlib the first working backend from a candidate list ["macosx", "qt5agg", "qt4agg", "gtk3agg", "tkagg", "wxagg"] is chosen.


2 Answers

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.

like image 179
CT Zhu Avatar answered Sep 21 '22 03:09

CT Zhu


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.

like image 21
dequation Avatar answered Sep 21 '22 03:09

dequation