function pictureoutliers(randfunc,n,nout,xcenter,N,alpha,mingap,fighandle)
% PICTUREOUTLIERS(RANDFUNC,N,NOUT,XCENTER,N,ALPHA,MINGAP)
% Draw a graph demonstrating spacing method of outlier detection
%
% RANDFUNC		Function to generate random variables. Must take 1 input,
%				the desired sample size.
%				Example: @(n)randn(1,n)
% N				Sample size of regular data
% NOUT			How many outliers to include, at 2*max of regular data
% XCENTER		Peak of regular data distribution (can be approximate)
% N				averaging block size for estimating gap
% ALPHA			significance level
% MINGAP		minimum gap size (useful if data has low precision)
% FIGHANDLE		figure to draw in; if not given, use current figure

% Generate the regular data
x = randfunc(n);

% Add outliers, if requested
xmax = max(x);
x = [x 2*xmax*ones(1,nout)];

% Histogram, show mean and std of sample
if exist('fighandle','var')
	figure;
end
hist(x,100), xlabel('value'), ylabel('count');
title(sprintf(...
	'Regular data generated by %s, n=%d,\nwith %d added outliers',...
	func2str(randfunc),n,nout))
yl = ylim;
xbar = mean(x); s = std(x);
line([xbar xbar],yl,'color','r')
text(xbar,yl(2),'mean','horiz','r','vert','top','rotation',90);

line([xbar+s xbar+s],yl,'color','r')
text(xbar+s,yl(2),'mean + \sigma','horiz','r','vert','top','rotation',90)
xmax = max(x);
text(xmax,2,...
	sprintf('x_{max} = mean + %.1f\\sigma',(xmax-xbar)/s),...
	'horiz','l','vert','c','rotation',90)

% Find the outliers
[thres,outlierindex] = findoutliers(x,xcenter,N,alpha,mingap);
if isnan(thres)
	text(xmax,yl(2)/2,'No Outliers','horiz','r','edgecolor','k')
else
	line([thres thres],yl,'color','g','linewidth',2)
	text(thres,yl(2)/2,sprintf('%d Outliers',sum(outlierindex)),...
		'horiz','r','vert','top','rotation',90,'backg','w')
end
