1

如果我这样做:

import seaborn as sns 
tips = sns.load_dataset("tips")                                                                                                                                       
ax = sns.violinplot(x="day", y="total_bill", data=tips)

4组不同颜色的小提琴图

如何改为通过不同的阴影更改颜色?我尝试了与箱线图相同的方法,但没有奏效。

4

1 回答 1

2

国际大学联盟:

import seaborn as sns
import matplotlib as mpl
tips = sns.load_dataset("tips")
hatch = ['/','\\','+','o']
ihatch = iter(hatch)
ax = sns.violinplot(x="day", y="total_bill", data=tips, color='g')
_ = [i.set_hatch(next(ihatch)) for i in ax.get_children() if isinstance(i, mpl.collections.PolyCollection)]

输出:

在此处输入图像描述

于 2019-12-12T15:09:37.713 回答