Skip to content

Instantly share code, notes, and snippets.

@dmcdougall
Created September 17, 2012 11:00
Show Gist options
  • Save dmcdougall/3736698 to your computer and use it in GitHub Desktop.
Save dmcdougall/3736698 to your computer and use it in GitHub Desktop.
Diff output from v0.90
1,2c1,4
< def boxplot(self, x, notch=0, sym='b+', vert=1, whis=1.5,
< positions=None, widths=None):
---
> def boxplot(self, x, notch=0, sym='+', vert=1, whis=1.5,
> positions=None, widths=None, means=0, fill=0,
> linestyle='-', monochrome=0, limits=None,
> notchsize=None):
5c7,9
< positions=None, widths=None)
---
> positions=None, widths=None, means=0, fill=0,
> linestyle='-', monochrome=0, limits=None,
> notchsize=None)
15c19,22
< notch = 1 will produce a notched box plot
---
> notch = 1 will produce a notched box plot.
> notch = 2 will additionally keep the notch size constant,
> replacing the box altogether with a notch if the box
> becomes smaller than the box limits.
17c24
< sym (default 'b+') is the default symbol for flier points.
---
> sym (default '+') is the default symbol for flier points.
35a43,60
> means = 0 (default) does not indicate the mean of the data.
> means = 1 plots a dashed black line in the box indicating
> the mean of the data.
>
> fill = 1 fills the box in white
> fill = 0 (default) leaves the box open
>
> linestyle sets the line style of the whiskers.
>
> monochrome = 0 (default) uses color in the plot.
> monochrome = 1 uses a monochrome color scheme.
>
> limits sets the axis limits for the plot (default = None for
> automatic setting)
>
> notchsize = None (default) -- unused unless notch == 2
> notchsize fixes a notch to be a constant size when notch == 2
>
38c63,64
< Returns a list of the lines added.
---
> Returns a dict of the lines added, keyed by 'boxes', 'caps',
> 'whiskers', 'medians', 'fliers', and 'means'.
43c69
< whiskers, caps, boxes, medians, fliers = [], [], [], [], []
---
> whiskers, caps, boxes, medians, fliers, means = [], [], [], [], [], []
79a106,107
> # get mean
> mean = sum(d)/len(d)
118c146
< # get y location for median
---
> # get y location for median, mean
119a148
> mean_y = [mean, mean]
121a151
> no_box = False
124c154
< box_x = [box_x_min, box_x_max, box_x_max, box_x_min, box_x_min ]
---
> box_x = [box_x_min, box_x_max, box_x_max, box_x_min, box_x_min]
126c156
< # make our median line vectors
---
> # make our median, mean line vectors
127a158
> mean_x = [box_x_min, box_x_max]
130,135c161,176
< notch_max = med + 1.57*iq/sqrt(row)
< notch_min = med - 1.57*iq/sqrt(row)
< if notch_max > q3:
< notch_max = q3
< if notch_min < q1:
< notch_min = q1
---
> if notch == 1:
> notch_max = med + 1.57*iq/sqrt(row)
> notch_min = med - 1.57*iq/sqrt(row)
> if notch_max > q3:
> notch_max = q3
> if notch_min < q1:
> notch_min = q1
> else:
> if notchsize is None:
> raise ValueError("Must supply notchsize when notch==2")
> notch_max = med + notchsize
> notch_min = med - notchsize
> # force 'no box' if notch size outside of box limits
> if notch_max > q3 or notch_min < q1:
> no_box = True
>
137,139c178,186
< box_x = [box_x_min, box_x_max, box_x_max, cap_x_max, box_x_max, box_x_max, box_x_min, box_x_min, cap_x_min, box_x_min, box_x_min ]
< box_y = [q1, q1, notch_min, med, notch_max, q3, q3, notch_max, med, notch_min, q1]
< # make our median line vectors
---
> if no_box:
> box_x = [box_x_max, cap_x_max, box_x_max]
> notch2_x = [box_x_min, cap_x_min, box_x_min]
> box_y = [notch_min, med, notch_max]
> notch2_y = [notch_max, med, notch_min]
> else:
> box_x = [box_x_min, box_x_max, box_x_max, cap_x_max, box_x_max, box_x_max, box_x_min, box_x_min, cap_x_min, box_x_min, box_x_min]
> box_y = [q1, q1, notch_min, med, notch_max, q3, q3, notch_max, med, notch_min, q1]
> # make our median, mean line vectors
141c188,196
< med_y = [med, med]
---
> mean_x = [box_x_min, box_x_max] # doesn't take into account notch shape
>
> if monochrome:
> wiskcol = capcol = boxcol = medcol = symcol = 'k'
> else:
> wiskcol, capcol, boxcol, medcol, symcol = 'b', 'k', 'b', 'r', 'b'
>
> if fill and not no_box:
> self.fill(box_x, box_y, facecolor='w')
154,161c209,224
< whiskers.extend(doplot(wisk_x, [q1, wisk_lo], 'b--',
< wisk_x, [q3, wisk_hi], 'b--'))
< caps.extend(doplot(cap_x, [wisk_hi, wisk_hi], 'k-',
< cap_x, [wisk_lo, wisk_lo], 'k-'))
< boxes.extend(doplot(box_x, box_y, 'b-'))
< medians.extend(doplot(med_x, med_y, 'r-'))
< fliers.extend(doplot(flier_hi_x, flier_hi, sym,
< flier_lo_x, flier_lo, sym))
---
> whiskers.extend(doplot(wisk_x, [q1, wisk_lo], wiskcol+linestyle,
> wisk_x, [q3, wisk_hi], wiskcol+linestyle))
> caps.extend(doplot(cap_x, [wisk_hi, wisk_hi], capcol+'-',
> cap_x, [wisk_lo, wisk_lo], capcol+'-'))
> boxes.extend(doplot(box_x, box_y, boxcol+'-'))
> medians.extend(doplot(med_x, med_y, medcol+'-'))
> fliers.extend(doplot(flier_hi_x, flier_hi, symcol+sym,
> flier_lo_x, flier_lo, symcol+sym))
> if means:
> if notch > 0:
> nstyle = 'k-'
> else:
> nstyle = 'k:'
> means.extend(doplot(mean_x, mean_y, nstyle))
> if notch == 2 and no_box:
> boxes.extend(doplot(notch2_x, notch2_y, boxcol+'-'))
169,171c232,239
< newlimits = min(positions)-0.5, max(positions)+0.5
< setlim(newlimits)
< setticks(positions)
---
> # use explicit axis limits if provided
> if limits is None:
> newlimits = min(positions)-0.5, max(positions)+0.5
> setlim(newlimits)
> setticks(positions)
> elif limits != ():
> setlim(limits)
> setticks([])
177c245,246
< medians=medians, fliers=fliers)
---
> medians=medians, fliers=fliers, means=means)
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment