88The following examples show off how to visualize boxplots with
99Matplotlib. There are many options to control their appearance and
1010the statistics that they use to summarize the data.
11-
1211"""
12+
1313import matplotlib .pyplot as plt
1414import numpy as np
1515from matplotlib .patches import Polygon
130130medians = np .empty (num_boxes )
131131for i in range (num_boxes ):
132132 box = bp ['boxes' ][i ]
133- boxX = []
134- boxY = []
133+ box_x = []
134+ box_y = []
135135 for j in range (5 ):
136- boxX .append (box .get_xdata ()[j ])
137- boxY .append (box .get_ydata ()[j ])
138- box_coords = np .column_stack ([boxX , boxY ])
136+ box_x .append (box .get_xdata ()[j ])
137+ box_y .append (box .get_ydata ()[j ])
138+ box_coords = np .column_stack ([box_x , box_y ])
139139 # Alternate between Dark Khaki and Royal Blue
140140 ax1 .add_patch (Polygon (box_coords , facecolor = box_colors [i % 2 ]))
141141 # Now draw the median lines back over what we just filled in
142142 med = bp ['medians' ][i ]
143- medianX = []
144- medianY = []
143+ median_x = []
144+ median_y = []
145145 for j in range (2 ):
146- medianX .append (med .get_xdata ()[j ])
147- medianY .append (med .get_ydata ()[j ])
148- ax1 .plot (medianX , medianY , 'k' )
149- medians [i ] = medianY [0 ]
146+ median_x .append (med .get_xdata ()[j ])
147+ median_y .append (med .get_ydata ()[j ])
148+ ax1 .plot (median_x , median_y , 'k' )
149+ medians [i ] = median_y [0 ]
150150 # Finally, overplot the sample averages, with horizontal alignment
151151 # in the center of each box
152152 ax1 .plot (np .average (med .get_xdata ()), np .average (data [i ]),
193193# We can then use the boxplot along with this function to show these intervals.
194194
195195
196- def fakeBootStrapper (n ):
196+ def fake_bootstrapper (n ):
197197 """
198198 This is just a placeholder for the user's method of
199199 bootstrapping the median and its confidence intervals.
200200
201- Returns an arbitrary median and confidence intervals
202- packed into a tuple
201+ Returns an arbitrary median and confidence interval packed into a tuple.
203202 """
204203 if n == 1 :
205204 med = 0.1
206- CI = (- 0.25 , 0.25 )
205+ ci = (- 0.25 , 0.25 )
207206 else :
208207 med = 0.2
209- CI = (- 0.35 , 0.50 )
210-
211- return med , CI
208+ ci = (- 0.35 , 0.50 )
209+ return med , ci
212210
213211inc = 0.1
214212e1 = np .random .normal (0 , 1 , size = 500 )
@@ -217,10 +215,10 @@ def fakeBootStrapper(n):
217215e4 = np .random .normal (0 , 1 + 2 * inc , size = 500 )
218216
219217treatments = [e1 , e2 , e3 , e4 ]
220- med1 , CI1 = fakeBootStrapper (1 )
221- med2 , CI2 = fakeBootStrapper (2 )
218+ med1 , ci1 = fake_bootstrapper (1 )
219+ med2 , ci2 = fake_bootstrapper (2 )
222220medians = [None , None , med1 , med2 ]
223- conf_intervals = [None , None , CI1 , CI2 ]
221+ conf_intervals = [None , None , ci1 , ci2 ]
224222
225223fig , ax = plt .subplots ()
226224pos = np .array (range (len (treatments ))) + 1
0 commit comments