import numpy as np
import numpy.random as npr
import matplotlib.pyplot as plt
x= npr.standard_normal(10000)
y = npr.normal(1,1, 10000)
from matplotlib import rcParams
rcParams['figure.figsize'] = 8,6
plt.hist(x, bins=35, color='g', edgecolor='w', alpha=.8)
plt.hist(y, bins=35, color='orange', edgecolor='w', alpha=.7)
plt.grid(axis='y', alpha=.4);
from scipy.stats import norm
plt.hist(x, bins=25, density=True, color = 'g', edgecolor='w', alpha=0.7);
overlay = np.linspace(x.min(), x.max(), 100)
mean, std = norm.fit(x)
pdf = norm.pdf(overlay, mean, std)
plt.xlim(-4,4)
plt.plot(overlay, pdf, 'r--');
plt.hist(x, bins=50, density=True, color ='g', edgecolor='w')
overlay = np.linspace(x.min(), x.max(), 100)
mean, std = norm.fit(x)
pdf = norm.pdf(overlay, mean, std)
plt.plot(overlay, pdf, 'r--')
plt.text(-3, .35, "$\mu$: {:.2f} \n$\sigma$: {:.2f}".format(mean, std),
bbox=dict(edgecolor='gray', facecolor='w'));
age_groups = {"under 5": 6.8, "5 to 17": 18.9, "18 to 24": 9.6, "25 to 44": 30.2, "45 to 64": 22, "over 65": 12.4}
sum(age_groups.values())
99.9
plt.title("Age Group Population Percentages", fontsize=18)
plt.grid(axis='y', alpha=.3)
plt.bar(age_groups.keys(), age_groups.values())
for k,v in age_groups.items():
plt.text(k,v-2, str(v), fontsize=14, fontweight='bold',
color='w', horizontalalignment='center');
plt.title("Age Group Population Percentages", fontsize=18)
plt.barh(list(age_groups.keys()), list(age_groups.values()))
for k,v in age_groups.items():
plt.text(v-4, k, str(v), fontsize=14, fontweight='bold',
color='w', verticalalignment='center')