violinplot


In [1]:
import matplotlib.pyplot as plt
import scipy.stats
import numpy as np
%matplotlib inline

In [2]:
rvs_norm = scipy.stats.norm.rvs(loc=4.0, scale=2.0, size=500)
rvs_binom = scipy.stats.binom.rvs(n=10, p=0.4, size=500)
rvs_expon = scipy.stats.expon.rvs(loc=2.0, scale=5.0, size=500)

In [3]:
f,a = plt.subplots()
violins = a.violinplot((rvs_norm, rvs_binom, rvs_expon), showmeans=True, showmedians=True)
a.set_xticks((1.0, 2.0, 3.0))
a.set_xticklabels(('Norm', 'Binomial', 'Exponential'))
violins['bodies'][0].set_facecolor('orange')
violins['bodies'][0].set_edgecolor('black')
violins['cmedians']


Out[3]:
<matplotlib.collections.LineCollection at 0x7fed23c2d9b0>

In [4]:
violins


Out[4]:
{'bodies': [<matplotlib.collections.PolyCollection at 0x7fed23c14630>,
  <matplotlib.collections.PolyCollection at 0x7fed23c14898>,
  <matplotlib.collections.PolyCollection at 0x7fed23c14b00>],
 'cmeans': <matplotlib.collections.LineCollection at 0x7fed26179630>,
 'cmaxes': <matplotlib.collections.LineCollection at 0x7fed23c2d080>,
 'cmins': <matplotlib.collections.LineCollection at 0x7fed23c2d358>,
 'cbars': <matplotlib.collections.LineCollection at 0x7fed23c2d630>,
 'cmedians': <matplotlib.collections.LineCollection at 0x7fed23c2d9b0>}

In [5]:
f,a = plt.subplots()
a.violinplot((rvs_norm, rvs_binom, rvs_expon), showmeans=True, showmedians=True, vert=False)
a.set_yticks((1.0, 2.0, 3.0))
a.set_yticklabels(('Norm', 'Binomial', 'Exponential'))


Out[5]:
[Text(0,0,'Norm'), Text(0,0,'Binomial'), Text(0,0,'Exponential')]