Seaborn provides of a handful of graphics which are very interesting for scientifical data representation. Thus I started using these Seaborn graphics interspersed with other customized matplotlib plots. The problem is that once I do:
import seaborn as sb
This import seems to set the graphic parameters for seaborn globally and then all matplotlib graphics below the import get the seaborn parameters (they get a grey background, linewithd changes, etc, etc).
In SO there is an answer explaining how to produce seaborn plots with matplotlib configuration, but what I want is to keep the matplotlib configuration parameters unaltered when using both libraries together and at the same time be able to produce, when needed, original seaborn plots.
As of seaborn version 0.8 (july 2017) the graph style is not altered anymore on import. The OP wish is now the default behaviour. From https://seaborn.pydata.org/whatsnew.html:
You can choose the style of any plot with plt.style.use().
More on plt.style() here
Restore all RC params to original settings (respects custom rc) is allowed by
seaborn.reset_orig()
functionAs explained in this other question you can import seaborn with:
And the matplotlib styles will not be modified.
If you never want to use the
seaborn
style, but do want some of the seaborn functions, you can import seaborn using this following line (documentation):If you want to produce some plots with the
seaborn
style and some without, in the same script, you can turn theseaborn
style off using theseaborn.reset_orig
function.It seems that doing the
apionly
import essentially setsreset_orig
automatically on import, so its up to you which is most useful in your use case.Here's an example of switching between
matplotlib
defaults andseaborn
:which produces the following three plots:
seaborn-off.png:
seaborn-on.png:
seaborn-offagain.png:
You may use the
matplotlib.style.context
functionality as described in the style guide.