简体   繁体   English

Seaborn未在导入时设置其默认调色板

[英]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 有很多链接表明Matplotlib的图表看起来更令人愉悦,因为seaborn的调色板只是通过导入seaborn就像

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. 但是,当我这样做时,颜色和格式仍然看起来像matplotlib的情节以及seaborn的简单matlotlib默认值。 That is unless the command sns.set() is executed to force reset the seaborn's default palette. 除非执行命令sns.set()以强制重置seaborn的默认调色板。

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. 如何安装seaborn:这发生在运行Anaconda的Ubuntu 14.04中,虽然seaborn是通过pip安装的,因为系统中的Anaconda版本没有预先安装它。 I tried installing seaborn through conda for both my environments, py27 and py35 . 我试图通过安装seaborn conda我的环境,无论是py27py35 Though the installation was successful, the import did not work, so I proceeded with pip . 虽然安装成功,但导入不起作用,所以我继续使用pip

Though seaborn works perfectly fine, both environments still import with the same unpleasing matplitlib default colours. 虽然seaborn工作得很好,但两种环境仍然导入相同的令人不愉快的matplitlib默认颜色。

You are using seaborn version 0.8 or higher. 您使用的是seaborn 0.8或更高版本。 The change log tells us: 更改日志告诉我们:

The default style is no longer applied when seaborn is imported. 导入seaborn时不再应用默认样式。 It is now necessary to explicitly call set() or one or more of set_style() , set_context() , and set_palette() . 现在需要显式调用set()set_style()set_context()set_palette()一个或多个。 Correspondingly, the seaborn.apionly module has been deprecated. 相应地,seaborn.apionly模块已被弃用。

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. 以前,只是因为你导入了seaborn它会完全改变matplotlib样式,甚至可能覆盖以前设置的matplotlib样式。 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 . 当你发现自己时,你需要调用seaborn.set()来获得seaborn的默认样式或使用任何其他seaborn样式

You can also use seaborn styles with matplotlib and not using seaborn at all. 您也可以使用matplotlib的seaborn样式,而不使用seaborn。 Eg 例如

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

or any other style from the style sheet reference 样式表参考中的任何其他样式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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