From ccabe197b38e324f32a7989bef1216c4bfb88863 Mon Sep 17 00:00:00 2001 From: Roger Herikstad Date: Sun, 27 Apr 2014 18:09:25 +0800 Subject: [PATCH 1/6] Adds type and functions for doing boxplots --- src/Winston.jl | 149 +++++++++++++++++++++++++++++++++++++++++++++++++ src/plot.jl | 41 ++++++++++++++ 2 files changed, 190 insertions(+) diff --git a/src/Winston.jl b/src/Winston.jl index c67f6c9..df3ffcd 100644 --- a/src/Winston.jl +++ b/src/Winston.jl @@ -2033,6 +2033,155 @@ function make(self::Histogram, context::PlotContext) GroupPainter(getattr(self,:style), PathPainter(u, v)) end +type Boxplot <: PlotComponent + attr::PlotAttributes + median::Float64 + quartiles::(Float64,Float64) + iqr::Float64 + outliers::AbstractVector + notch::Bool + width::Float64 + n::Int64 + position::Float64 + + + function Boxplot(median, quartiles, outliers, n,args...; kvs...) + self = new(Dict()) + iniattr(self) + kw_init(self, args...; kvs...) + self.median = median + self.quartiles = quartiles + self.iqr = quartiles[2] - quartiles[1] + self.outliers = filter(x-> (xquartiles[2]+1.5*self.iqr),outliers) + self.notch = get(args2dict(kvs...), :notch, false) + self.width=1.0 + self.position = 1.0 + self.n = n + self + end +end + +function Boxplot(X::Vector;kvs...) + #compute median and quartiles directly + Xs = sort(X) + m = median(X) + l = quantile(X,0.25) + h = quantile(X,0.75) + iqr = h-l + Boxplot(m,(l,h),X[(X.>h+1.5*iqr)&(X. Date: Sun, 27 Apr 2014 18:18:24 +0800 Subject: [PATCH 2/6] Adds exporting of new function boxplot and type Boxplot --- src/Winston.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Winston.jl b/src/Winston.jl index df3ffcd..922b71e 100644 --- a/src/Winston.jl +++ b/src/Winston.jl @@ -19,6 +19,7 @@ export plot, plothist, plothist2d, + boxplot, savefig, scatter, semilogx, @@ -37,7 +38,8 @@ export FramedPlot, Plot, Table, - + + Boxplot, Curve, FillAbove, FillBelow, From 6e2adc7c07521bbcaa259d9781a75faa22097547 Mon Sep 17 00:00:00 2001 From: Roger Herikstad Date: Sun, 27 Apr 2014 18:28:48 +0800 Subject: [PATCH 3/6] Fixes a problem where outliers were not plotted --- src/Winston.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Winston.jl b/src/Winston.jl index 922b71e..09a26bf 100644 --- a/src/Winston.jl +++ b/src/Winston.jl @@ -2054,7 +2054,7 @@ type Boxplot <: PlotComponent self.median = median self.quartiles = quartiles self.iqr = quartiles[2] - quartiles[1] - self.outliers = filter(x-> (xquartiles[2]+1.5*self.iqr),outliers) + self.outliers = filter(x-> (xquartiles[2]+1.5*self.iqr),outliers) self.notch = get(args2dict(kvs...), :notch, false) self.width=1.0 self.position = 1.0 @@ -2070,7 +2070,7 @@ function Boxplot(X::Vector;kvs...) l = quantile(X,0.25) h = quantile(X,0.75) iqr = h-l - Boxplot(m,(l,h),X[(X.>h+1.5*iqr)&(X.h+1.5*iqr)|(X. Date: Fri, 9 May 2014 10:22:07 +0800 Subject: [PATCH 4/6] Change name from 'boxplot' to 'quartilebox' --- src/Winston.jl | 16 ++++++++-------- src/plot.jl | 22 +++++++++++----------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Winston.jl b/src/Winston.jl index 09a26bf..a7deab1 100644 --- a/src/Winston.jl +++ b/src/Winston.jl @@ -19,7 +19,7 @@ export plot, plothist, plothist2d, - boxplot, + quartileboxes, savefig, scatter, semilogx, @@ -39,7 +39,7 @@ export Plot, Table, - Boxplot, + QuartileBoxes, Curve, FillAbove, FillBelow, @@ -2035,7 +2035,7 @@ function make(self::Histogram, context::PlotContext) GroupPainter(getattr(self,:style), PathPainter(u, v)) end -type Boxplot <: PlotComponent +type QuartileBoxes <: PlotComponent attr::PlotAttributes median::Float64 quartiles::(Float64,Float64) @@ -2047,7 +2047,7 @@ type Boxplot <: PlotComponent position::Float64 - function Boxplot(median, quartiles, outliers, n,args...; kvs...) + function QuartileBoxes(median, quartiles, outliers, n,args...; kvs...) self = new(Dict()) iniattr(self) kw_init(self, args...; kvs...) @@ -2063,17 +2063,17 @@ type Boxplot <: PlotComponent end end -function Boxplot(X::Vector;kvs...) +function QuartileBoxes(X::Vector;kvs...) #compute median and quartiles directly Xs = sort(X) m = median(X) l = quantile(X,0.25) h = quantile(X,0.75) iqr = h-l - Boxplot(m,(l,h),X[(X.>h+1.5*iqr)|(X.h+1.5*iqr)|(X. Date: Fri, 9 May 2014 10:22:26 +0800 Subject: [PATCH 5/6] Add documentation for quartileboxes --- doc/fun/quartileboxes.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 doc/fun/quartileboxes.rst diff --git a/doc/fun/quartileboxes.rst b/doc/fun/quartileboxes.rst new file mode 100644 index 0000000..42f9af8 --- /dev/null +++ b/doc/fun/quartileboxes.rst @@ -0,0 +1,14 @@ +quartileboxes +======= + +.. function:: quartileboxes(x [;notch=false]) + + Visualize the distribution ``x``. If ``x`` is a matrix, visualize each column. The median of ``x`` is represented by a horizontal line inside a box extending from the 25th to the 75th percentile of ``x``. Vertical lines, called whiskers, span 1.5 times the inter-quartile range. Data outside of this range are represented as dots. If the keyword argument ``notch`` is set to ``true``, a notch is drawn around around the median to indicate the confidence of the median. + +Examples +======= + +.. winston:: + + X = rand((200,10)) + quartileboxes(X ;notch=true) From dcfa706754c33f7616ec2c7a41f3efb35eedbd5f Mon Sep 17 00:00:00 2001 From: Roger Herikstad Date: Tue, 13 May 2014 16:03:14 +0800 Subject: [PATCH 6/6] Adds quartileboxes to NEWS --- NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS b/NEWS index 1b25b78..ad4a703 100644 --- a/NEWS +++ b/NEWS @@ -5,3 +5,5 @@ v0.11.0 (2014 Apr XX) * Added stem() function and Stems component. +* Added quartileboxes() function and QuartileBoxes component +