我想在抖动剥离图后面绘制小提琴图。结果图的抖动点后面有平均值/标准杆,很难看清。我很想知道是否有办法使标准更加突出。
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.violinplot(x="day", y="total_bill", data=tips, color="0.8")
sns.stripplot(x="day", y="total_bill", data=tips, jitter=True)
plt.show()
答案 0 :(得分:1)
Seaborn并不关心将其创建的对象暴露给用户。因此,需要从轴上收集它们以进行操作。您要在此处更改的属性是zorder
。因此,想法可能是
示例:
import seaborn as sns
import matplotlib.pyplot as plt
from matplotlib.collections import PathCollection
tips = sns.load_dataset("tips")
ax = sns.violinplot(x="day", y="total_bill", data=tips, color=".8")
for artist in ax.lines:
artist.set_zorder(10)
for artist in ax.findobj(PathCollection):
artist.set_zorder(11)
sns.stripplot(x="day", y="total_bill", data=tips, jitter=True, ax=ax)
plt.show()
答案 1 :(得分:1)
我遇到了同样的问题,可以通过调整zorder
中的sns.stripplot
参数来解决此问题:
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.violinplot(x="day", y="total_bill", data=tips, color="0.8")
sns.stripplot(x="day", y="total_bill", data=tips, jitter=True, zorder=1)
plt.show()