63

I'm using seaborn version o.4 and matplotlib version 1.42 I have a chart displays both line and marker through simple plot command eg.

plt.plot([1,5,3,8,4],'-bo');

Due to a potential bug (https://github.com/mwaskom/seaborn/issues/344), after import seaborn, same code shows line only without marker.

import seaborn as sb 
plt.plot([1,5,3,8,4],'-bo');

So my question is: after import seaborn, Is there a way to reset all the parameters back to original?

user3287545
  • 1,911
  • 5
  • 20
  • 19

7 Answers7

51

Yes, call seaborn.reset_orig.

mwaskom
  • 46,693
  • 16
  • 125
  • 127
  • 16
    This sort-of works, but plots made after `import seaborn` and `seaborn.reset_orig()` still look quite different to plots made before these lines. Is there a way to get rid of all seaborn effects, as if it had never been imported? – user2428107 Oct 11 '15 at 01:02
39

None of these solutions worked for me (Python 3.x, Jupyter). What worked was matplotlib.rc_file_defaults()

See the documentation here: https://matplotlib.org/stable/api/matplotlib_configuration_api.html#matplotlib.rc_file_defaults

Chong Onn Keat
  • 520
  • 2
  • 8
  • 19
Marcelo Modesto
  • 416
  • 4
  • 2
  • 3
    This solution worked for me with Python 3. `seaborn.reset_orig` did not work. – Mead Jan 14 '21 at 21:33
  • 1
    The correct link is now https://matplotlib.org/stable/api/matplotlib_configuration_api.html#matplotlib.rc_file_defaults – Ilya Apr 26 '21 at 23:05
11

To refresh Matplotlib's configuration side effects often encountered with Seaborn:

import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns

Run this:

import importlib
importlib.reload(mpl); importlib.reload(plt); importlib.reload(sns)

For old Python2 code:

import imp
imp.reload(mpl); imp.reload(plt); imp.reload(sns)

Note: None of the following correctly restores the state of matplotlib:

  • sns.reset_orig()
  • sns.reset_defaults()
  • mpl.rcParams.update(mpl.rcParamsDefault)
Joel Bondurant
  • 841
  • 1
  • 10
  • 17
  • `Importlib` imports fine, but when I try using `reload` I get `AttributeError: 'module' object has no attribute 'reload'`. Is this only available in Python 3.x? – lanery Aug 29 '16 at 23:43
  • doh, updated for Python 2: import imp; imp.reload(somemodule) – Joel Bondurant Aug 30 '16 at 23:59
  • 3
    For anyone reading this in the near future: I tried this with several different versions of matplotlib and seaborn inside Jupyter and could not get it to work, I don't think this is a general solution (maybe it used to be). – Peter Feb 20 '19 at 21:08
5

You can save the rcParams you want, before changing the style with seaborn (note that seaborn no longer changes the rcParams upon import):

import matplotlib as mpl

my_params = mpl.rcParams

# apply some change to the rcparams here

mpl.rcParams.update(my_params)

Note that both these

mpl.rcParams.update(mpl.rcParamsOrig)
mpl.rcParams.update(mpl.rcParamsDefault)

restores almost all rcParams to their default value. The few that will be different can easily be viewed by (I ran this in a Jupyter Notebook):

# Differences between current params and `Default`
for key in mpl.rcParamsDefault:
    if not mpl.rcParamsDefault[key] == mpl.rcParams[key]:
        print(key, mpl.rcParamsDefault[key], mpl.rcParams[key])

## backend agg module://ipykernel.pylab.backend_inline
## figure.dpi 100.0 72.0
## figure.edgecolor w (1, 1, 1, 0)
## figure.facecolor w (1, 1, 1, 0)
## figure.figsize [6.4, 4.8] [6.0, 4.0]
## figure.subplot.bottom 0.11 0.125

and

# Differences between `Default` and `Orig`
for key in mpl.rcParamsDefault:
    if not mpl.rcParamsDefault[key] == mpl.rcParamsOrig[key]:
        print(key, mpl.rcParamsDefault[key], mpl.rcParamsOrig[key])

## backend agg Qt5Agg
joelostblom
  • 43,590
  • 17
  • 150
  • 159
5

In my case I was searching to reset the plot sizes of the output specifically when I changed using the rc attribute used the following code to reset to default size sns.reset_defaults() (where sns is seaborn).

F Blanchet
  • 1,430
  • 3
  • 21
  • 32
Eswar Chitirala
  • 486
  • 6
  • 14
5

You can set them back to default by doing:

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

Also, check this post from Jake VanderPlas to learn more about customizing matplotlib.

Hope it helps!

Franco D'Angelo
  • 115
  • 3
  • 9
-4

One can simply call the seaborn.set() function, with no function parameters, see [seaborn tutorial][1].

tagoma
  • 3,896
  • 4
  • 38
  • 57