2016-11-21 299 views
4

我试图用不同的x组和另外的hues seaborn产生boxplot。看到此代码:Seaborn的boxplot + swarmplot:不同的颜色为x,不同的颜色符号

tips = sns.load_dataset("tips") 

sns.stripplot(x="day", y="total_bill", hue="smoker", 
       data=tips, jitter=True, 
       palette="Set2", split=True,linewidth=1,edgecolor='gray') 

sns.boxplot(x="day", y="total_bill", hue="smoker", 
      data=tips,palette="Set2",fliersize=0) 

enter image description here

我想有各x箱图(在该示例中,每一天)是不同的颜色,而每个hue(在这种情况下,吸烟者/非吸烟者)在大面积上用不同的符号表示。

我试图玩palette的论点,但没有得到我想要的。我也尝试直接玩artists,但是改变boxplot的facecolor也会因为某种原因改变edgecolor,我不知道如何改变swarmplot上的符号。

回答

0

你的问题的着色部分:边缘颜色和facecolor都可以通过艺术家单独指定。

ax = sns.boxplot(x="day", y="total_bill", hue="smoker", 
      data=tips,fliersize=0) 

colors = sns.color_palette('husl',n_colors=4) 
colors = sp.repeat(colors,2,axis=0) 

for artist,color in zip(ax.artists,colors): 
    artist.set_facecolor(color) 
    artist.set_edgecolor(color) 

而对于条纹:我也无法找到如何偶然的制造商。如果你想指定他们的颜色等,你可以通过[pc for pc in ax.get_children() if type(pc) == PathCollection]单独获取它们全部...