2016-02-29 144 views
2

我第一次使用seaborn,并试图制作一个嵌套(分组)的boxplot,其数据点添加为点。这里是我的代码:将splitplot(dotplot)添加到分组boxplot中 - Panda和Seaborn

import seaborn as sns 
import pandas as pd 
import matplotlib.pyplot as plt 
tips = sns.load_dataset("tips") 
sns.set(style="ticks") 
## Draw a nested boxplot to show bills by day and sex 
sns.boxplot(x="day", y="total_bill", hue="smoker",data=tips,width=0.5,palette="PRGn",linewidth=1) 

## Draw a split strip plot 
sns.stripplot(x="day", y="total_bill", hue="smoker",palette="PRGn",data=tips,size=4,edgecolor="gray", 
      split=True) 
sns.despine(offset=10, trim=True) 
plt.show() 

而且数字:enter image description here

您可以看到点并不集中在货箱,因为在箱线图使用的“宽度”参数。有什么办法可以将点与盒子对齐吗? boxplot命令中的宽度参数是未对齐点的原因。

p.s. - 我已经添加了汤姆提到的MCVE。

八德

+0

(https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.stripplot.html)它们似乎是居中(虽然在一个水平的,而不是垂直的情节)。也许你可以在你的问题中添加一个[MCVE](http://stackoverflow.com/help/mcve)来重现这种行为? – tom

+0

@tom:我添加了这个例子。 – Bade

回答

0

组之间的距离自动计算,有没有简单的方法来改变它,我知道的,但使用的是一种间接的方式来修改它在箱线图:关键字width。使用默认值,一切都会对齐。

sns.set(style="ticks") 
sns.boxplot(x="day", y="total_bill", hue="smoker", data=tips, 
      palette="PRGn", linewidth=1) 
sns.stripplot(x="day", y="total_bill", hue="smoker", data=tips, 
       palette="PRGn", size=4, edgecolor="gray", split=True) 
sns.despine(offset=10, trim=True) 

aligned plot

在向[当前页]底部的示例