Home > atmlab > graphs > satboxplot.m

satboxplot

PURPOSE ^

satboxplot Modified boxplot

SYNOPSIS ^

function h=satboxplot(x, y, bincentres, outlierstyle, varargin)

DESCRIPTION ^

 satboxplot Modified boxplot

 Alternative boxplot. Bins the data (in y) according to bins (in xbin).
 For each bin, plots the median (by default a horizontal red line),
 a box connecting to the 25th and 75th percentile, and whiskers extending
 to the 1st and 99th percentile. All other data are considered outliers
 and plotted individually. To change what the result looks like, add
 additional arguments that will be passed on to <a href="matlab:help boxplot">boxplot</a>

 FORMAT

   h = satboxplot(x, y, xbin, outlierstyle, ...)

 IN

   x               numeric array
                   Data according to which y is binned.
   y               numeric array
                   Data for which statistics are carried out, binned
                   according to the values of x, etc.
   bincentres      Bin centres for x 
   outlierstyle    Style for outliers, e.g. 'kx'
   ...     all additional arguments passed on to <a href="matlab:help boxplot">boxplot</a>

 OUT

  h                numeric scalar, plot handle
                   handle to outliers (for other handles, see <a href="matlab:help boxplot">boxplot</a>)

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

satboxplot.m

SOURCE CODE ^

0001 function h=satboxplot(x, y, bincentres, outlierstyle, varargin)
0002 
0003 % satboxplot Modified boxplot
0004 %
0005 % Alternative boxplot. Bins the data (in y) according to bins (in xbin).
0006 % For each bin, plots the median (by default a horizontal red line),
0007 % a box connecting to the 25th and 75th percentile, and whiskers extending
0008 % to the 1st and 99th percentile. All other data are considered outliers
0009 % and plotted individually. To change what the result looks like, add
0010 % additional arguments that will be passed on to <a href="matlab:help boxplot">boxplot</a>
0011 %
0012 % FORMAT
0013 %
0014 %   h = satboxplot(x, y, xbin, outlierstyle, ...)
0015 %
0016 % IN
0017 %
0018 %   x               numeric array
0019 %                   Data according to which y is binned.
0020 %   y               numeric array
0021 %                   Data for which statistics are carried out, binned
0022 %                   according to the values of x, etc.
0023 %   bincentres      Bin centres for x
0024 %   outlierstyle    Style for outliers, e.g. 'kx'
0025 %   ...     all additional arguments passed on to <a href="matlab:help boxplot">boxplot</a>
0026 %
0027 % OUT
0028 %
0029 %  h                numeric scalar, plot handle
0030 %                   handle to outliers (for other handles, see <a href="matlab:help boxplot">boxplot</a>)
0031 %
0032 % $Id$
0033 
0034 binedges = [-inf (bincentres(1:end-1)+bincentres(2:end))/2 inf];
0035 values_cell = bin(x, y, binedges);
0036 % convert values to a matrix with binned values in the columns, rest nans
0037 maxsize = max(cellfun(@length, values_cell));
0038 vals_mapped = cellfun(@(v) [v; nan(maxsize-length(v), 1)], values_cell(1:end-1), 'UniformOutput', false);
0039 values = horzcat(vals_mapped{:});
0040 
0041 q = quantile(values, [0.01 0.25 0.5 0.75 0.99]);
0042 
0043 for c = 1:size(values, 2)
0044     toosmall = values(:, c) < q(1, c);
0045     toolarge = values(:, c) > q(5, c);
0046     outliers = [values(toosmall, c); values(toolarge, c)];
0047     all_outliers(1:length(outliers), c) = outliers;
0048 end
0049 
0050 all_outliers(all_outliers==0)=nan;
0051 hold on;
0052 boxplot(q, bincentres, 'positions', bincentres, 'labelorientation', 'inline', 'whisker', inf, varargin{:});
0053 set(gca,'xtickmode','auto','xticklabelmode','auto');
0054 if ~isempty(all_outliers)
0055     h=plot(bincentres, all_outliers, outlierstyle);
0056 else
0057     h = -1;
0058 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005