Generating histograms and box plots
Matplotlib supports the creation of a variety of displays of data. In this recipe, we will demonstrate how to use two popular graphs representing data variability: histograms and box plots (also known as box-and-whisker plots). We will present a comparison between the distribution of heights in the male and female populations. To make the example self-contained, instead of using real data, we will simulate a population with the known distribution of heights for males and females.
Getting ready
Start Jupyter and run the following three commands in an execution cell:
%matplotlib inline import numpy as np import matplotlib.pyplot as plt
How to do it…
Run the following code in a Jupyter code cell:
from scipy.stats import norm mmean, msdev = 70, 4.0 fmean, fsdev = 65, 3.5 mdist = norm(mmean, scale=msdev) fdist = norm(fmean, scale=fsdev) nm, nf = 2000, 1500 mdata = mdist.rvs(size=nm) fdata = fdist.rvs(size=nf) plt.figure(figsize=(12, 4)) plt.subplot(1,2,1) plt.hist...