Mercurial > hg > medcouple
comparison talk/code/plots.py @ 45:6daaf6a8e431
Add code to plot boys and girls
author | Jordi GutiƩrrez Hermoso <jordigh@octave.org> |
---|---|
date | Sat, 14 May 2016 21:24:47 -0400 (2016-05-15) |
parents | |
children | 7887a0b32539 |
comparison
equal
deleted
inserted
replaced
44:83f8cf24a8e3 | 45:6daaf6a8e431 |
---|---|
1 import matplotlib.pyplot as plt | |
2 import matplotlib.cbook as cbook | |
3 import numpy as np | |
4 | |
5 with open("../../data/men") as f: | |
6 men = [float(x) for x in f.readlines()] | |
7 | |
8 with open("../../data/women") as f: | |
9 women = [float(x) for x in f.readlines()] | |
10 | |
11 men_stats = cbook.boxplot_stats(men) | |
12 women_stats = cbook.boxplot_stats(women) | |
13 | |
14 fig = plt.figure(figsize=(6,4)) | |
15 | |
16 # setup the figure and axes | |
17 bpAx = fig.add_axes([0.05, 0.7, 0.4, 0.2]) # left, bottom, width, height: | |
18 # (adjust as necessary) | |
19 histAx = fig.add_axes([0.05, 0.2, 0.4, 0.5]) # left specs should match and | |
20 # bottom + height on this line should | |
21 # equal bottom on bpAx line | |
22 # plot stuff | |
23 bpAx.bxp(men_stats, vert=False, flierprops={"marker": 'x'}) | |
24 histAx.hist(men, bins=100, color=[0.3, 0.3, 1]) | |
25 | |
26 # confirm that the axes line up | |
27 xlims = np.array([bpAx.get_xlim(), histAx.get_xlim()]) | |
28 for ax in [bpAx, histAx]: | |
29 ax.set_xlim([xlims.min(), xlims.max()]) | |
30 | |
31 bpAx.set_xticklabels([]) # clear out overlapping xlabels | |
32 bpAx.set_yticks([]) # don't need that 1 tick mark | |
33 bpAx.set_title("Ages of actors") | |
34 | |
35 | |
36 | |
37 # setup the figure and axes | |
38 bpAx = fig.add_axes([0.55, 0.7, 0.4, 0.2]) # left, bottom, width, height: | |
39 # (adjust as necessary) | |
40 histAx = fig.add_axes([0.55, 0.2, 0.4, 0.5]) # left specs should match and | |
41 # bottom + height on this line should | |
42 # equal bottom on bpAx line | |
43 # plot stuff | |
44 bpAx.bxp(women_stats, vert=False, flierprops={"marker": 'x'}) | |
45 histAx.hist(women, bins=100, color='pink') | |
46 | |
47 # confirm that the axes line up | |
48 xlims = np.array([bpAx.get_xlim(), histAx.get_xlim()]) | |
49 for ax in [bpAx, histAx]: | |
50 ax.set_xlim([xlims.min(), xlims.max()]) | |
51 | |
52 bpAx.set_xticklabels([]) # clear out overlapping xlabels | |
53 bpAx.set_yticks([]) # don't need that 1 tick mark | |
54 bpAx.set_title("Ages of actresses") | |
55 | |
56 plt.show() |