2017-04-16 34 views
4

我想用Python的Seaborn软件包绘制多个黑白盒装图。默认情况下,图是使用调色板。我想用纯黑色的轮廓绘制它们。我能想出的最好的是:Seaborn中的黑白盒装图

# figure styles 
sns.set_style('white') 
sns.set_context('paper', font_scale=2) 
plt.figure(figsize=(3, 5)) 
sns.set_style('ticks', {'axes.edgecolor': '0', 
         'xtick.color': '0', 
         'ytick.color': '0'}) 

ax = sns.boxplot(x="test1", y="test2", data=dataset, color='white', width=.5) 
sns.despine(offset=5, trim=True) 
sns.plt.show() 

将会产生类似:

enter image description here

我希望来框为黑色,而不在调色板任何填充或变更。

回答

4

你必须设置每个箱子的edgecolor和半年线(须和中位数)与每一个框关联使用set_color

ax = sns.boxplot(x="day", y="total_bill", data=tips, color='white', width=.5, fliersize=0) 

# iterate over boxes 
for i,box in enumerate(ax.artists): 
    box.set_edgecolor('black') 
    box.set_facecolor('white') 

    # iterate over whiskers and median lines 
    for j in range(6*i,6*(i+1)): 
     ax.lines[j].set_color('black') 

如果采用过去的周期对所有艺术家和线条那么它可能是根据boxplot

plt.setp(ax.artists, edgecolor = 'k', facecolor='w') 
plt.setp(ax.lines, color='k') 

其中ax:减少到。

enter image description here

如果您还需要设置传单颜色遵循这一answer

+1

如果你想得到真正的极简主义,你可以做'showbox = False'。 – mwaskom