简体   繁体   中英

Seaborn is not setting its default color palette on import

There are many links which state that Matplotlib's plots would look more pleasing due to seaborn's color palette just by importing seaborn like

import seaborn as sns

However, when I do this, the colors and formatting still looks like plain matlotlib defaults for both matplotlib's plot as well as that of seaborn. That is unless the command sns.set() is executed to force reset the seaborn's default palette.

Why is this happening and how to fix this?

How seaborn was installed: This happens in my Ubuntu 14.04 running Anaconda, although seaborn was installed through pip since the Anaconda version in the system did not come with it preinstalled. I tried installing seaborn through conda for both my environments, py27 and py35 . Though the installation was successful, the import did not work, so I proceeded with pip .

Though seaborn works perfectly fine, both environments still import with the same unpleasing matplitlib default colours.

You are using seaborn version 0.8 or higher. The change log tells us:

The default style is no longer applied when seaborn is imported. It is now necessary to explicitly call set() or one or more of set_style() , set_context() , and set_palette() . Correspondingly, the seaborn.apionly module has been deprecated.

There is a very good reason for this. Previously, just because you imported seaborn it would completely alter the matplotlib style, possibly even overwriting previously set matplotlib styles. Both is usually undesired.

As you found out yourself, you need to call seaborn.set() to get the default style of seaborn or use any other of the seaborn styles .

You can also use seaborn styles with matplotlib and not using seaborn at all. Eg

import matplotlib.pyplot as plt
plt.style.use("seaborn-darkgrid")

or any other style from the style sheet reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM