changeset 53:874eb0823660

plots: ensure that adjusted boxplots use the same scale
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Mon, 16 May 2016 22:27:30 -0400
parents 242afe8021b4
children bb6e5cf6aa83
files talk/code/plots.py
diffstat 1 files changed, 14 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/talk/code/plots.py
+++ b/talk/code/plots.py
@@ -12,6 +12,17 @@
     histheight = 0.75*height
     boxheight = 0.25*height
 
+    # setup the figure and axes
+    histAx = fig.add_axes([left, bottom, width, histheight])
+    bpAx = fig.add_axes([left, bottom+histheight, width, boxheight])
+
+    # plot stuff
+    bpAx.bxp(data_stats, vert=False, flierprops={"marker": 'x'})
+    histAx.hist(data, bins=bins, color=colour)
+
+
+    xlims = np.array([bpAx.get_xlim(), histAx.get_xlim()])
+
     # Do an adjusted boxplot
     if adjusted:
         mc = medcouple_1d(data)
@@ -33,17 +44,10 @@
             if (flier < data_stats[0]['whislo']  or
                 flier > data_stats[0]['whishi'])
         ]
-
-    # setup the figure and axes
-    histAx = fig.add_axes([left, bottom, width, histheight])
-    bpAx = fig.add_axes([left, bottom+histheight, width, boxheight])
-
-    # plot stuff
-    bpAx.bxp(data_stats, vert=False, flierprops={"marker": 'x'})
-    histAx.hist(data, bins=bins, color=colour)
+        bpAx.cla()
+        bpAx.bxp(data_stats, vert=False, flierprops={"marker": 'x'})
 
     # 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()])
 
@@ -63,7 +67,7 @@
 with open("../../data/women") as f:
     women = [float(x) for x in f.readlines()]
 
-fig = plt.figure(figsize=(12,8))
+
 xticks = np.arange(5,105,5)
 bins = 0.5 + np.arange(0,100)