-
Notifications
You must be signed in to change notification settings - Fork 2
/
areabar.m
84 lines (71 loc) · 2.07 KB
/
areabar.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
function handles = areabar(xvalues,ydata,error,c1,alpha,varargin)
%Plots X and Y value data with error bar shown as a shaded
%area. Use:
%
% areabar(x,y,error,c1,alpha,plotoptions)
%
% where c1 is the colour of the shaded options and plotoptions are
% passed to the line plot
if nargin < 3
error('You need to add at least X, Y and ERROR vectors as input!');
end
if min(size(xvalues)) > 1 || min(size(ydata)) > 1 || min(size(error)) > 2
warning('Sorry, you can only plot vector data.')
error('Areabar error');
end
if strcmpi(get(gca,'NextPlot'),'add')
NextPlot = 'add';
else
NextPlot = 'replacechildren';
end
if nargin <4 || isempty(c1) || ischar(c1)
c1=[0.5 0.5 0.5];
end
if nargin < 5 || isempty(alpha) || ischar(alpha)
if exist('alpha','var') && ischar(alpha)
[varargin{2:end+1}]=varargin{1:end};
varargin{1} = alpha;
end
alpha = 0.25;
end
if nargin < 6 && isempty(varargin)
%varargin{1} = 'k-o';
%varargin{2} = 'MarkerFaceColor';
%varargin{3} = [0 0 0];
end
x=size(xvalues);
y=size(ydata);
e=size(error);
%need to organise to rows
if x(1) < x(2); xvalues=xvalues'; end
if y(1) < y(2); ydata=ydata'; end
if e(1) < e(2); error=error'; end
idx=find(isnan(ydata));
ydata(idx)=[];
xvalues(idx)=[];
error(idx,:)=[];
error(isnan(error)) = 0;
x=length(xvalues);
if size(error,2) == 2
err=zeros(x+x,1);
err(1:x,1)=error(:,1);
err(x+1:x+x,1)=flipud(error(:,2));
else
err=zeros(x+x,1);
err(1:x,1)=ydata+error;
err(x+1:x+x,1)=flipud(ydata-error);
end
areax=zeros(x+x,1);
areax(1:x,1)=xvalues;
areax(x+1:x+x,1)=flipud(xvalues);
axis auto
if max(c1) > 1; c1 = c1 / max(c1); end
handles.fill = fill(areax,err,c1,'EdgeColor','none','FaceAlpha',alpha);
set(get(get(handles.fill,'Annotation'),'LegendInformation'),'IconDisplayStyle','off'); % Exclude line from legend
handles.axis = (gca);
set(gca,'NextPlot','add');
handles.plot = plot(xvalues,ydata,'Color', c1/2, varargin{:});
set(gca,'NextPlot',NextPlot);
%set(gca,'PlotBoxAspectRatioMode','manual');
uistack(handles.plot,'top')
set(gca,'Layer','bottom');