-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplot_patch.m
More file actions
84 lines (72 loc) · 1.92 KB
/
Copy pathplot_patch.m
File metadata and controls
84 lines (72 loc) · 1.92 KB
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 varargout = plot_patch(varargin)
% PLOT_PATCH Plots stacked (default) patches of timeseries (or whatever).
% [h1,h2] = plot_patch(timesteps/wpewce/mass(1),[UB_ts; Uke1_ts; Uke2_ts; Uki1_ts; Uki2_ts; Ute1_ts; Ute2_ts; Uti1_ts; Uti2_ts],'base',0);
% legend(h1,{'UB','Uke1','Uke2','Uki1','Uki2','Ute1','Ute2','Uti1','Uti2'})
[ax,args,nargs] = axescheck(varargin{:});
if isempty(ax), ax = gca; end
doSort = 0;
doColors = 0;
doStacked = 1;
doBase = 0; % add zero level
x = args{1}; args = args(2:end);
y = args{1}; args = args(2:end);
while ~isempty(args)
switch args{1}
case 'sort'
doSort = 1;
sortOption = args{2};
l = 2;
case {'color','colors'}
doColors = 1;
colors = args{2};
if size(colors,1) < (size(y,1)-1)
warning(sprintf('Insufficient number of colors provided. Recycling %g times.',ceil((size(y,1)-1)/size(colors,1))))
colors = repmat(colors,ceil((size(y,1)-1)/size(colors,1)),1);
end
l = 2;
case 'base'
doBase = 1;
base = args{2};
l = 2;
end
args = args((l+1):end);
end
if doSort
[~,ind_sort] = sort(y(:,1),1,sortOption);
y = y(ind_sort,:);
end
y = cumsum(y,1);
%y = y-repmat(y(:,1),1,size(y,2));
if doBase
yBase = repmat(base,1,size(y,2));
yBase(isnan(y(1,:))) = NaN;
y = [yBase; y];
end
nComps = size(y,1);
hl = plot(ax,x,y(2:end,:));
if doColors
for iLine = 1:numel(hl)
hl(iLine).Color = colors(iLine,:);
end
end
hold(ax,'on')
for iComp = 1:(nComps-1)
xPatch = [x, NaN, x(end:-1:1)];
yPatch = [y(iComp,:), NaN, y(iComp+1,end:-1:1)];
isNan = isnan(yPatch);
xPatch(isNan) = [];
yPatch(isNan) = [];
hp = patch(ax,xPatch,yPatch,'k','Parent', ax);
hp.FaceAlpha = 0.5;
hp.EdgeColor = hl(iComp).Color*0;
hp.FaceColor = hl(iComp).Color;
hp_out(iComp,1) = hp;
end
hold(ax,'off')
switch nargout
case 1
varargout(1) = {hp_out};
case 2
varargout(1) = {hp_out};
varargout(2) = {hl};
end