python – Seaborn没有在导入时设置其默认调色板

有很多链接表明Matplotlib的图表看起来更令人愉悦,因为seaborn的调色板只是通过导入seaborn就像

import seaborn as sns

但是,当我这样做时,颜色和格式仍然看起来像matplotlib的情节以及seaborn的简单matlotlib默认值.除非执行命令sns.set()以强制重置seaborn的默认调色板.

为什么会发生这种情况以及如何解决这个问题?

如何安装seaborn:
这种情况发生在运行Anaconda的Ubuntu 14.04中,虽然seaborn是通过pip安装的,因为系统中的Anaconda版本没有预先安装它.我尝试通过conda为我的环境py27和py35安装seaborn.虽然安装成功,但导入不起作用,所以我继续使用pip.

虽然seaborn工作得很好,但两种环境仍然导入相同的令人不愉快的matplitlib默认颜色.

解决方法:

您使用的是seaborn 0.8或更高版本. change log告诉我们:

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.

这是有充分理由的.以前,只是因为你导入了seaborn它会完全改变matplotlib样式,甚至可能覆盖以前设置的matplotlib样式.两者通常都是不受欢迎的.

当您发现自己时,需要调用seaborn.set()来获取默认的seaborn样式或使用seaborn styles中的任何其他样式.

您也可以使用matplotlib的seaborn样式,而不使用seaborn.例如.

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

style sheet reference的任何其他款式

上一篇:python – 具有加权数据的分布型图(histogram / kde)


下一篇:python – seaborn plot_marginals多个kdeplots