Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib differentiate between mean and median with colour or shape

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:

like image 765
James Lloyd Avatar asked Oct 29 '25 11:10

James Lloyd


1 Answers

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

enter image description here

like image 138
Stop harming Monica Avatar answered Oct 31 '25 00:10

Stop harming Monica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!