[422372]: / functions / miscfunc / fillcurves.m

Download this file

127 lines (116 with data), 4.4 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
 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
123
124
125
126
% FILLCURVES - fill the space between 2 curves
%
% Usage:
% h=fillcurves( Y1, Y2);
% h=fillcurves( X, Y1, Y2, color, transparent[0 to 1]);
%
% Example:
% a = rand(1, 50);
% b = rand(1, 50)+2; b(10) = NaN;
% figure; fillcurves([51:100], a, b);
%
% Author: A. Delorme, SCCN, INC, UCSD/CERCO, CNRS
% Copyright (C) Arnaud Delorme, arno@salk.edu
%
% This file is part of EEGLAB, see http://www.eeglab.org
% for the documentation and details.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%
% 1. Redistributions of source code must retain the above copyright notice,
% this list of conditions and the following disclaimer.
%
% 2. Redistributions in binary form must reproduce the above copyright notice,
% this list of conditions and the following disclaimer in the documentation
% and/or other materials provided with the distribution.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
% THE POSSIBILITY OF SUCH DAMAGE.
function h = fillcurves(X, Y1, Y2, color, transparent, legends)
if nargin < 2
help fillcurves;
return;
end
if nargin < 3
Y2 = Y1;
Y1 = X;
X = [1:length(Y1)];
end
if nargin < 4 || isempty(color)
color = { 'r' 'b' 'g' 'c' };
elseif ~iscell(color)
color = { color };
end
if nargin < 5
transparent = 0.5;
end
X1 = X(:)';
X2 = X(:)';
% remove NaNs
tmpnan1 = find(isnan(Y1));
tmpnan2 = find(isnan(Y2));
Y1(tmpnan1) = []; X1(tmpnan1) = [];
Y2(tmpnan2) = []; X2(tmpnan2) = [];
% remove 0s if log scale
if strcmpi(get(gca, 'yscale'), 'log')
tmp1 = find(~Y1);
tmp2 = find(~Y2);
Y1(tmp1) = []; X1(tmp1) = [];
Y2(tmp2) = []; X2(tmp2) = [];
end
% multiple curve plot
% -------------------
if size(Y1,1) ~= 1 && size(Y1,2) ~= 1
for index = 1:size(Y1,2)
fillcurves(X, Y1(:,index)', Y2(:,index)', color{index}, transparent);
hold on;
end
% yl = ylim;
% xl = xlim;
% line([xl(1) xl(1)]+(xl(2)-xl(1))/2000, yl, 'color', 'k');
% line(xl, [yl(1) yl(1)]+(yl(2)-yl(1))/2000, 'color', 'k');
% write legend and add transparency to it
% ---------------------------------------
if nargin > 5
h = legend(legends);
hh = get(h, 'children');
for index = 1:length(hh)
fields = get(hh(index));
if isfield(fields, 'FaceAlpha');
numfaces = size(get(hh(index), 'Vertices'),1);
set(hh(index), 'FaceVertexCData', repmat([1 1 1], [numfaces 1]), 'Cdatamapping', 'direct', 'facealpha', transparent, 'edgecolor', 'none');
end
end
end
return;
end
% plot
% ----
allpointsx = [X1 X2(end:-1:1)]';
allpointsy = [Y1 Y2(end:-1:1)]';
h = fill(allpointsx, allpointsy, color{1});
set(h, 'edgecolor', color{1});
xlim([ X(1) X(end) ]);
if transparent
numfaces = size(get(h, 'Vertices'),1);
set(h, 'FaceVertexCData', repmat([1 1 1], [numfaces 1]), 'Cdatamapping', 'direct', 'facealpha', transparent, 'edgecolor', 'none');
end
% replot lines at boundaries
% --------------------------
% parent = dbstack;
% if length(parent) == 1 || ~strcmpi(parent(2).name, 'fillcurves')
% yl = ylim;
% xl = xlim;
% line([xl(1) xl(1)]+(xl(2)-xl(1))/2000, yl, 'color', 'k');
% line(xl, [yl(1) yl(1)]+(yl(2)-yl(1))/2000, 'color', 'k');
% end