# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1463275487 14400 # Node ID 6daaf6a8e4315442d7a9ce4e2c28fd8844b6d108 # Parent 83f8cf24a8e37b56511fd423282a7c01d3a5d1c1 Add code to plot boys and girls diff --git a/talk/code/plots.py b/talk/code/plots.py new file mode 100644 --- /dev/null +++ b/talk/code/plots.py @@ -0,0 +1,56 @@ +import matplotlib.pyplot as plt +import matplotlib.cbook as cbook +import numpy as np + +with open("../../data/men") as f: + men = [float(x) for x in f.readlines()] + +with open("../../data/women") as f: + women = [float(x) for x in f.readlines()] + +men_stats = cbook.boxplot_stats(men) +women_stats = cbook.boxplot_stats(women) + +fig = plt.figure(figsize=(6,4)) + +# setup the figure and axes +bpAx = fig.add_axes([0.05, 0.7, 0.4, 0.2]) # left, bottom, width, height: + # (adjust as necessary) +histAx = fig.add_axes([0.05, 0.2, 0.4, 0.5]) # left specs should match and + # bottom + height on this line should + # equal bottom on bpAx line +# plot stuff +bpAx.bxp(men_stats, vert=False, flierprops={"marker": 'x'}) +histAx.hist(men, bins=100, color=[0.3, 0.3, 1]) + +# confirm that the axes line up +xlims = np.array([bpAx.get_xlim(), histAx.get_xlim()]) +for ax in [bpAx, histAx]: + ax.set_xlim([xlims.min(), xlims.max()]) + +bpAx.set_xticklabels([]) # clear out overlapping xlabels +bpAx.set_yticks([]) # don't need that 1 tick mark +bpAx.set_title("Ages of actors") + + + +# setup the figure and axes +bpAx = fig.add_axes([0.55, 0.7, 0.4, 0.2]) # left, bottom, width, height: + # (adjust as necessary) +histAx = fig.add_axes([0.55, 0.2, 0.4, 0.5]) # left specs should match and + # bottom + height on this line should + # equal bottom on bpAx line +# plot stuff +bpAx.bxp(women_stats, vert=False, flierprops={"marker": 'x'}) +histAx.hist(women, bins=100, color='pink') + +# confirm that the axes line up +xlims = np.array([bpAx.get_xlim(), histAx.get_xlim()]) +for ax in [bpAx, histAx]: + ax.set_xlim([xlims.min(), xlims.max()]) + +bpAx.set_xticklabels([]) # clear out overlapping xlabels +bpAx.set_yticks([]) # don't need that 1 tick mark +bpAx.set_title("Ages of actresses") + +plt.show()