在子图中改变matplotlib小提琴图的颜色

时间:2016-12-28 19:48:26

标签: python matplotlib violin-plot

我试图改变小提琴情节中的平均颜色,如下所示:Matplotlib differentiate between mean and median with colour or shape

但我的小提琴情节是一个副图,这不起作用。我有办法做到这一点吗?

这是我的代码:

fig, axes = plt.subplots(figsize = (16, 7), ncols = 2)
fig.suptitle('Distribution of Domain Lengths', size = 18)

axes[0].boxplot(human_pfam_domains['length'], showmeans = True)

axes[1].violinplot(human_pfam_domains['length'], showmeans = True, showmedians=True, vert=True, points= 500)

axes[1]['cmeans'].set_color('b')

和错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-62-22cdd9b07029> in <module>()
  6 axes[1].violinplot(human_pfam_domains['length'], showmeans = True, showmedians=True, vert=True, points= 500)
  7 
----> 8 axes[1]['cmeans'].set_color('b')

TypeError: 'AxesSubplot' object has no attribute '__getitem_

谢谢!

1 个答案:

答案 0 :(得分:1)

linked solution 建议,你需要处理小提琴字典,就像这样

ScriptProcessorNode