python - 如何在seaborn fiddle 图上添加阴影?

标签 python seaborn violin-plot hatchstyle

如果我做类似的事情:

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

Violin plot with 4 groups in different colors

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

最佳答案

IIUC:

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)]

输出:

enter image description here

关于python - 如何在seaborn fiddle 图上添加阴影?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59307192/

相关文章:

python - 如何通过消除成对的连续互补方向来从给定方向列表返回简化的方向列表?

python - Django:创建动态表单

python - 在另一个方法中运行一个方法。 Python

python - 安装 Caffe 时遇到问题

python - Seaborn 直方图 bin 宽度未扩展到 bin 标签

r - 在 fiddle 图的填充条件下将散点与线配对

python - 让seaborn条形图中的颜色与轴中的标签相匹配

python - Seaborn 分类数据条形图,分组

python - 如何将绘图在 xticks 上居中对齐

python - Matplotlib fiddle 图在同一列上重叠