How to do it…

Run the following code in an execution cell:

from scipy.stats import gamma
distr = gamma(2.0)
xvalues = np.linspace(0, 10, 100)
yvalues = distr.pdf(xvalues)
plt.plot(xvalues, yvalues, color='orange')
plt.title('Mean and median')
plt.xlabel('$x$')
plt.ylabel('$f(x)$')
xmean = distr.mean()
ymean = distr.pdf(xmean)
xmed = distr.median()
ymed = distr.pdf(xmed)
aprops = dict(arrowstyle = '->')
plt.annotate('Median={:3.2f}'.format(xmed),
(xmed, ymed),
(xmed+1, ymed+0.03),
arrowprops=aprops)
plt.annotate('Mean={:3.2f}'.format(xmean),
(xmean, ymean),
(xmean+1, ymean+0.03),
arrowprops=aprops)
comment = '''In a skewed distribution,
mean and median usually
have different values.'''
plt.text(4.5, 0.15, comment, fontsize=12, color='blue')
None

Running this code creates the graph of a skewed probability distribution, with annotations showing where the Mean and Median are located, as shown in the following screenshot:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset