-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShadedErrorbar.m
52 lines (45 loc) · 1.08 KB
/
ShadedErrorbar.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
function h = ShadedErrorbar(X, Y, E, varargin)
% ShadedErrorbar(X, Y, E, parms)
%
% INPUTS
% X = x-data
% Y = y-data
% E = errors (assumed to be symmetric)
%
% PARMS
% color = 'k'
% marker = '.'
% L = E
% U = E
%
% If you want non-symmetric errorbars, redefine L and U.
color = 'k';
marker = '.';
lineStyle = '-';
lineWidth = 2;
L = E;
U = E;
faceAlpha = 0.25;
process_varargin(varargin);
% make sure all are n x 1
if size(X,1)==1, X = X'; end
if size(Y,1)==1, Y = Y'; end
if size(L,1)==1, L = L'; end
if size(U,1)==1, U = U'; end
H = ishold;
if ~H
cla
end
hold on
keep = ~isnan(X + L + U);
X = X(keep); L = Y(keep)-L(keep); U = Y(keep)+U(keep); Y = Y(keep);
h0 = patch([X; X(end:-1:1); X(1)], [L; U(end:-1:1); L(1)], 'k');
set(h0, 'FaceColor', color, 'EdgeColor', 'None', 'FaceAlpha', 0.25);
h0 = patch([X; X(end:-1:1); X(1)], [L; U(end:-1:1); L(1)], 'k');
set(h0, 'FaceColor', color, 'EdgeColor', 'None', 'FaceAlpha', faceAlpha);
h = plot(X, Y, 'Color', color, 'Marker', marker, 'LineWidth', lineWidth, 'LineStyle', lineStyle);
if H
hold on;
else
hold off;
end