python seaborn to reset back to the matplotlib

PythonMatplotlibMarkerSeaborn

Python Problem Overview


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

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

after_seaborn.png

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

Python Solutions


Solution 1 - Python

Yes, call seaborn.reset_orig.

Solution 2 - Python

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

Solution 3 - Python

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)

Solution 4 - Python

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

Solution 5 - Python

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!

Solution 6 - Python

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

Solution 7 - Python

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser3287545View Question on Stackoverflow
Solution 1 - PythonmwaskomView Answer on Stackoverflow
Solution 2 - PythonMarcelo ModestoView Answer on Stackoverflow
Solution 3 - PythonJoelBondurantView Answer on Stackoverflow
Solution 4 - PythonEswar ChitiralaView Answer on Stackoverflow
Solution 5 - PythonFranco D'AngeloView Answer on Stackoverflow
Solution 6 - PythonjoelostblomView Answer on Stackoverflow
Solution 7 - PythontagomaView Answer on Stackoverflow