-
Notifications
You must be signed in to change notification settings - Fork 70
/
demo_shadedErrorBar.m
123 lines (79 loc) · 2.35 KB
/
demo_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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
function demo_shadedErrorBar
% demo function for shadedErrorBar
%
% function demo_shadedErrorBar
%
% No input or output arguments.
%
%
% Rob Campbell
rows=2;
cols=2;
clf
subplot(rows,cols,1)
%Plot the mean and standard deviation then overlay the raw data
y=randn(30,80)*5;
x=(1:size(y,2))-40;
yP = sin( linspace(-2*pi,2*pi,length(x)) )*20;
y = bsxfun(@plus,y,yP)+60;
shadedErrorBar(x,y,{@mean,@std});
hold on
plot(x,y,'.','color',[0.5,0.5,0.95])
hold off
grid on
subplot(rows,cols,2)
%Overlay different lines (transparent) lines and change their properties
hold on
plot2styles = {'-b';'-g'; '-r'};
for i = 1:3
plt2invis = plot(0,0,plot2styles{i});
set( plt2invis, 'visible', 'off');
end
x=(1:size(y,2))-40;
y=ones(30,1)*x;
y=y+0.06*y.^2+randn(size(y))*10;
shadedErrorBar(x,y,{@mean,@std},'lineprops','-b','transparent',true,'patchSaturation',0.9)
shadedErrorBar(x,2*y+20,{@mean,@std},'lineprops',{'-go','MarkerFaceColor','g'},'transparent',true,'patchSaturation',0.9);
y=randn(30,80)*5;
x=(1:size(y,2))-40;
yP = sin( linspace(-2*pi,2*pi,length(x)) )*20;
y = bsxfun(@plus,y,yP)+60;
%Make red line non-transparent
shadedErrorBar(x, y, {@mean,@std}, 'lineprops', '-r','transparent',false,'patchSaturation',0.075)
hold off
legend(['#1';'#2';'#3'],'location','northwest')
legend
grid on
subplot(rows,cols,3)
% Post-hoc modifications of line properties
y=randn(30,80)*5;
x=(1:size(y,2));
yP = sin( linspace(-2*pi,2*pi,length(x)) )*20;
y = bsxfun(@plus,y,yP);
%Set face and edge properties
if (sum( size(ver('MATLAB'))) > 0 )
s = shadedErrorBar(x, y, {@mean,@std}, 'lineprops', '-r');
set(s.edge,'LineWidth',2,'LineStyle',':')
s.mainLine.LineWidth = 5;
s.patch.FaceColor = [0.5,0.25,0.25];
elseif (sum(size(ver('Octave'))) > 0)
s = shadedErrorBar(x, y, {@mean,@std}, 'lineprops', {'-r','LineWidth',5,'LineStyle',':'});
end
hold on
if (sum( size(ver('MATLAB'))) > 0 )
plot(s.mainLine.XData, s.mainLine.YData,'or','MarkerFaceColor','w')
end
hold off
grid on
set(gca,'XTickLabel',[],'YTickLabel',[])
subplot(rows,cols,4)
% Post-hoc modifications of line properties
y=randn(256,80)*5;
x=(1:size(y,2));
yP = cos( linspace(-2*pi,2*pi,length(x)) )*10;
y = bsxfun(@plus,y,yP);
shadedErrorBar(x, y, {@mean,@std}, 'lineprops', '-r')
hold on
y=mean(y)+16;
errbar = [2*ones(1,length(x)) ; 4*ones(1,length(x))];
shadedErrorBar(x, y, errbar, 'lineprops', '-g')