source: LMDZ6/trunk/libf/phylmd/ecrad/test/i3rc/herrorbar.m @ 5040

Last change on this file since 5040 was 4773, checked in by idelkadi, 11 months ago
  • Update of Ecrad in LMDZ The same organization of the Ecrad offline version is retained in order to facilitate the updating of Ecrad in LMDZ and the comparison between online and offline results. version 1.6.1 of Ecrad (https://github.com/lguez/ecrad.git)
  • Implementation of the double call of Ecrad in LMDZ


File size: 3.8 KB
Line 
1function hh = herrorbar(x, y, l, u, symbol)
2%HERRORBAR Horizontal Error bar plot.
3%   HERRORBAR(X,Y,L,R) plots the graph of vector X vs. vector Y with
4%   horizontal error bars specified by the vectors L and R. L and R contain the
5%   left and right error ranges for each point in X. Each error bar
6%   is L(i) + R(i) long and is drawn a distance of L(i) to the right and R(i)
7%   to the right the points in (X,Y). The vectors X,Y,L and R must all be
8%   the same length. If X,Y,L and R are matrices then each column
9%   produces a separate line.
10%
11%   HERRORBAR(X,Y,E) or HERRORBAR(Y,E) plots X with error bars [X-E X+E].
12%   HERRORBAR(...,'LineSpec') uses the color and linestyle specified by
13%   the string 'LineSpec'. See PLOT for possibilities.
14%
15%   H = HERRORBAR(...) returns a vector of line handles.
16%
17%   Example:
18%      x = 1:10;
19%      y = sin(x);
20%      e = std(y)*ones(size(x));
21%      herrorbar(x,y,e)
22%   draws symmetric horizontal error bars of unit standard deviation.
23%
24%   This code is based on ERRORBAR provided in MATLAB.   
25%
26%   See also ERRORBAR
27
28%   Jos van der Geest
29%   email: jos@jasen.nl
30%
31%   File history:
32%   August 2006 (Jos): I have taken back ownership. I like to thank Greg Aloe from
33%   The MathWorks who originally introduced this piece of code to the
34%   Matlab File Exchange.
35%   September 2003 (Greg Aloe): This code was originally provided by Jos
36%   from the newsgroup comp.soft-sys.matlab:
37%   http://newsreader.mathworks.com/WebX?50@118.fdnxaJz9btF^1@.eea3ff9
38%   After unsuccessfully attempting to contact the orignal author, I
39%   decided to take ownership so that others could benefit from finding it
40%   on the MATLAB Central File Exchange.
41
42if min(size(x))==1,
43    npt = length(x);
44    x = x(:);
45    y = y(:);
46    if nargin > 2,
47        if ~isstr(l),
48            l = l(:);
49        end
50        if nargin > 3
51            if ~isstr(u)
52                u = u(:);
53            end
54        end
55    end
56else
57    [npt,n] = size(x);
58end
59
60if nargin == 3
61    if ~isstr(l)
62        u = l;
63        symbol = '-';
64    else
65        symbol = l;
66        l = y;
67        u = y;
68        y = x;
69        [m,n] = size(y);
70        x(:) = (1:npt)'*ones(1,n);;
71    end
72end
73
74if nargin == 4
75    if isstr(u),
76        symbol = u;
77        u = l;
78    else
79        symbol = '-';
80    end
81end
82
83if nargin == 2
84    l = y;
85    u = y;
86    y = x;
87    [m,n] = size(y);
88    x(:) = (1:npt)'*ones(1,n);;
89    symbol = '-';
90end
91
92u = abs(u);
93l = abs(l);
94
95if isstr(x) | isstr(y) | isstr(u) | isstr(l)
96    error('Arguments must be numeric.')
97end
98
99if ~isequal(size(x),size(y)) | ~isequal(size(x),size(l)) | ~isequal(size(x),size(u)),
100    error('The sizes of X, Y, L and U must be the same.');
101end
102
103if strcmp(get(gca,'ylimmode'),'manual')
104  my_ylim = ylim;
105  index = find(y >= my_ylim(1) & y <= my_ylim(2));
106  tee = (max(y(index)) - min(y(index)))/100;
107else
108  tee = (max(y(:))-min(y(:)))/100 % make tee .02 x-distance for error bars
109end
110% changed from errorbar.m
111xl = x - l;
112xr = x + u;
113ytop = y + tee;
114ybot = y - tee;
115n = size(y,2);
116% end change
117
118% Plot graph and bars
119hold_state = ishold;
120cax = newplot;
121next = lower(get(cax,'NextPlot'));
122
123% build up nan-separated vector for bars
124% changed from errorbar.m
125xb = zeros(npt*9,n);
126xb(1:9:end,:) = xl;
127xb(2:9:end,:) = xl;
128xb(3:9:end,:) = NaN;
129xb(4:9:end,:) = xl;
130xb(5:9:end,:) = xr;
131xb(6:9:end,:) = NaN;
132xb(7:9:end,:) = xr;
133xb(8:9:end,:) = xr;
134xb(9:9:end,:) = NaN;
135
136yb = zeros(npt*9,n);
137yb(1:9:end,:) = ytop;
138yb(2:9:end,:) = ybot;
139yb(3:9:end,:) = NaN;
140yb(4:9:end,:) = y;
141yb(5:9:end,:) = y;
142yb(6:9:end,:) = NaN;
143yb(7:9:end,:) = ytop;
144yb(8:9:end,:) = ybot;
145yb(9:9:end,:) = NaN;
146% end change
147
148
149[ls,col,mark,msg] = colstyle(symbol); if ~isempty(msg), error(msg); end
150symbol = [ls mark col]; % Use marker only on data part
151esymbol = ['-' col]; % Make sure bars are solid
152
153h = plot(xb,yb,esymbol); hold on
154h = [h;plot(x,y,symbol)];
155
156if ~hold_state, hold off; end
157
158if nargout>0, hh = h; end
Note: See TracBrowser for help on using the repository browser.