Matplotlib用颜色或形状区分均值和中位数 [英] Matplotlib differentiate between mean and median with colour or shape
本文介绍了Matplotlib用颜色或形状区分均值和中位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是matplotlib版本1.4.3,我想制作一个Violinplot,我想显示均值和中位数,这很容易做到,但我想标记均值和中位数,以便可以轻松地区分它们,通过更改其中一个的颜色和/或形状,但是我在文档中看不到允许这样做的任何内容.
I am using matplotlib version 1.4.3 and I wanted to make a Violinplot and I wanted to show the mean and the median, which is easy to do but I want to mark the mean and median so they can easily be distinguished between, by changing the colour and/or shape of one of them but I cannot see anything in the documentation that allows for that.
任何帮助将不胜感激.
Anyhelp would be greatly appreciated.
violinplot(x, showmeans=True, showmedians=False, widths=1.0, showextrema=False)
带有平均值和中位数的小提琴图示例:
Example Violinplot with means and medians:
推荐答案
提示:在查看方法的文档字符串时,请不要错过Returns
部分.
Hint: when looking at a method's docstring never miss the Returns
part.
data = np.random.weibull(1.5, size=(1000, 3))
r = plt.violinplot(dataset=data, showmeans=True, showmedians=True,
widths=1.0, showextrema=False)
r['cmeans'].set_color('b')
r['cmedians'].set_color('g')
这篇关于Matplotlib用颜色或形状区分均值和中位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文