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 + 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) diff --git a/src/Winston.jl b/src/Winston.jl index c67f6c9..a7deab1 100644 --- a/src/Winston.jl +++ b/src/Winston.jl @@ -19,6 +19,7 @@ export plot, plothist, plothist2d, + quartileboxes, savefig, scatter, semilogx, @@ -37,7 +38,8 @@ export FramedPlot, Plot, Table, - + + QuartileBoxes, Curve, FillAbove, FillBelow, @@ -2033,6 +2035,155 @@ function make(self::Histogram, context::PlotContext) GroupPainter(getattr(self,:style), PathPainter(u, v)) end +type QuartileBoxes <: PlotComponent + attr::PlotAttributes + median::Float64 + quartiles::(Float64,Float64) + iqr::Float64 + outliers::AbstractVector + notch::Bool + width::Float64 + n::Int64 + position::Float64 + + + function QuartileBoxes(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 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 + QuartileBoxes(m,(l,h),X[(X.>h+1.5*iqr)|(X.