2015-12-16 39 views
2

seaborn是一个美丽的Python包,大部分作为matplotlib之上的附加层。但是,它会改变,例如,将对图表对象上的matplotlib方法指示seaborn函数。在Python的Seaborn中,有没有什么办法可以做“despine”的反义词?


seaborndespine()从曲线图中删除任何棘(图的外边缘)。但我不能做相反的事情。

我似乎无法以标准的方式重新创建脊柱,如果我从一开始就完全使用matplotlib,我会/可以。有没有办法做到这一点?我会怎么样?


下面是一个例子。例如,我可以在剧情的底部和左侧添加脊椎吗?

from sklearn import datasets 
import pandas as pd 

tmp = datasets.load_iris() 
iris = pd.DataFrame(tmp.data, columns=tmp.feature_names) 
iris['species'] = tmp.target_names[tmp.target] 
iris.species = iris.species.astype('category') 

import seaborn as sns 
import matplotlib.pyplot as plt 
sns.set_style('darkgrid') 
sns.boxplot(x='species', y='sepal length (cm)', data=iris_new) 
plt.show() 

associated boxplot

+1

的'darkgrid'风格在默认情况下没有刺。你需要选择另一种风格 - matplotlib现在有许多自己的风格。你也可以通过导入seaborn.apionly作为sns来导入seaborn而不会对样式产生任何影响。 –

+1

Paul是正确的,尽管完整的答案有点微妙。 'despine'实际上删除了脊柱物体,而'darkgrid'风格将'axes.linewidth'(又名棘)设置为0.你可以在默认的'darkgrid'之上指定额外的rc参数,或者选择不同的样式。 – mwaskom

+0

@mwaskom感谢澄清。非常好知道。 –

回答

4

感谢所有伟大的意见!我知道你们当中有些人写的东西,但不是说'axes.linewidth''axes.edgecolor'需要设置。

我在这里写一个答案,因为它是一些评论的汇编。


也就是说,下面的代码生成下面的情节:

sns.set_style('darkgrid', {'axes.linewidth': 2, 'axes.edgecolor':'black'}) 
sns.boxplot(x='species', y='sepal length (cm)', data=iris_new) 
plt.show() 

enter image description here

+1

如果你使用深灰色(即“.15”')而不是“黑色”,那么BTW的东西看起来会更好一些。这是真的[一般](http://ianstormtaylor.com/design-tip-never-use-black/),特别是因为那是其他seaborn剧情元素的颜色。 – mwaskom

+0

谢谢,@mwaskom!我同意。然而,就我的例子而言,我希望尽可能简化代码,而不是在我的主要问题之外引入概念。 –

相关问题