changeset 46:7887a0b32539

put the two boxplots above each other
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Sat, 14 May 2016 23:28:59 -0400
parents 6daaf6a8e431
children 1b15b9a0f336
files talk/code/plots.py
diffstat 1 files changed, 19 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/talk/code/plots.py
+++ b/talk/code/plots.py
@@ -11,17 +11,18 @@
 men_stats = cbook.boxplot_stats(men)
 women_stats = cbook.boxplot_stats(women)
 
-fig = plt.figure(figsize=(6,4))
+fig = plt.figure(figsize=(12,8))
 
 # setup the figure and axes
-bpAx = fig.add_axes([0.05, 0.7, 0.4, 0.2])   # left, bottom, width, height:
+bpAx = fig.add_axes([0.05, 0.8, 0.9, 0.1])   # left, bottom, width, height:
                                             # (adjust as necessary)
-histAx = fig.add_axes([0.05, 0.2, 0.4, 0.5]) # left specs should match and
+histAx = fig.add_axes([0.05, 0.55, 0.9, 0.25]) # 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])
+histAx.hist(men, bins=0.5 + np.arange(0,100), color=[0.3, 0.3, 1])
+
 
 # confirm that the axes line up
 xlims = np.array([bpAx.get_xlim(), histAx.get_xlim()])
@@ -30,19 +31,23 @@
 
 bpAx.set_xticklabels([])  # clear out overlapping xlabels
 bpAx.set_yticks([])  # don't need that 1 tick mark
-bpAx.set_title("Ages of actors")
+bpAx.set_title("Ages of actors",fontsize=20)
+
+histAx.set_xticks(np.arange(5,105,5))
+histAx.get_xaxis().tick_bottom()
+bpAx.get_xaxis().tick_top()
 
 
 
 # setup the figure and axes
-bpAx = fig.add_axes([0.55, 0.7, 0.4, 0.2])   # left, bottom, width, height:
+bpAx = fig.add_axes([0.05, 0.35, 0.9, 0.1])   # left, bottom, width, height:
                                             # (adjust as necessary)
-histAx = fig.add_axes([0.55, 0.2, 0.4, 0.5]) # left specs should match and
+histAx = fig.add_axes([0.05, 0.1, 0.9, 0.25]) # 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')
+histAx.hist(women, bins=0.5 + np.arange(0,100), color='pink')
 
 # confirm that the axes line up
 xlims = np.array([bpAx.get_xlim(), histAx.get_xlim()])
@@ -51,6 +56,10 @@
 
 bpAx.set_xticklabels([])  # clear out overlapping xlabels
 bpAx.set_yticks([])  # don't need that 1 tick mark
-bpAx.set_title("Ages of actresses")
+bpAx.set_title("Ages of actresses", fontsize=20)
 
-plt.show()
+histAx.set_xticks(np.arange(5,105,5))
+histAx.get_xaxis().tick_bottom()
+bpAx.get_xaxis().tick_top()
+
+plt.savefig("boys-and-girls.pdf")