Comparison of two Gaussian distributions

import numpy as np import matplotlib.pyplot as plt def normal_dist(x, mu, sigma): return (1 / (2*np.pi*sigma**2)**0.5)*np.exp(-(x-mu)**2/(2*sigma**2)) a = [13, 15, 45, 22, 28, 19, 16, 7, 31, 45, 71, 55, 63] b = [24, 33, 41, 37, 39, 61, 18, 59, 46, 52, 63, 25, 18] amean, astd = np.mean(a), np.std(a) bmean, bstd = np.mean(b), np.std(b) min_all = min(min(a), min(b)) max_all = max(max(a), max(b)) xs = range(min_all, max_all) agaussian = [normal_dist(i, amean, astd) for i in xs] bgaussian = [normal_dist(j, bmean, bstd) for j in xs] fig, ax = plt.subplots(figsize=(7, 5)) ax.set_title('Comparison of two Gaussian distributions') plt.plot(xs, agaussian, '-', color='blue', label='a') plt.plot(xs, bgaussian, '-', color='red', label='b') amax = normal_dist(amean, amean, astd) bmax = normal_dist(bmean, bmean, bstd) plt.plot([amean]*2, [0, amax], ls='--', lw=0.75, color='blue') plt.plot([bmean]*2, [0, bmax], ls='--', lw=0.75, color='red') max_peaks = max(amax, bmax) plt.xlim(min_all, max_all - 1) plt.ylim(0, 1.1*max_peaks) plt.text(1.1*min_all, 1.05*max_peaks, r'$\mu(a): %.3f, \sigma(a): %.3f$' % (amean, astd), color='blue') plt.text(1.1*min_all, max_peaks, r'$\mu(a): %.3f, \sigma(a): %.3f$' % (bmean, bstd), color='red') plt.legend(loc='best', frameon=False) plt.tight_layout() plt.show() A diagram showing two Gaussian distributions