在Python的Seaborn中,有没有办法做与“despine”相反的事情?

Mik*_*son 4 python matplotlib seaborn

seaborn是一个漂亮的 Python 包,它在很大程度上充当matplotlib. 然而,它改变了,例如,matplotlib绘图对象上的方法来指导seaborn函数。


seaborn从绘图中删除任何脊柱(绘图的外边缘)despine() 但我不能反其道而行之。

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()
Run Code Online (Sandbox Code Playgroud)

关联箱线图

Mik*_*son 6

感谢所有的精彩评论!我知道你写的一些内容,但不知道和需要设置。'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()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • 顺便说一句,如果您使用深灰色(即“.15”)而不是“黑色”,事情看起来会更好一些。[一般情况下](http://ianstormtaylor.com/design-tip-never-use-black/) 这都是正确的,特别是因为这是其他 seaborn 情节元素的颜色。 (2认同)