comparison scripts/plot/__bar__.m @ 6540:9dcfc78da664

[project @ 2007-04-18 21:16:08 by dbateman]
author dbateman
date Wed, 18 Apr 2007 21:16:08 +0000
parents
children cb3f6d51b7b3
comparison
equal deleted inserted replaced
6539:bfb71a842496 6540:9dcfc78da664
1 ## Copyright (C) 1996, 1997 John W. Eaton
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 2, or (at your option)
8 ## any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, write to the Free
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 ## 02110-1301, USA.
19
20 ## -*- texinfo -*-
21 ## @deftypefn {Function File} {} __bar__ (@dots{})
22 ## Support function for @ode{bar} and {hbar}.
23 ## @seealso{bar, hbar}
24 ## @end deftypefn
25
26 ## Author: jwe
27
28 function varargout = __bar__ (vertical, func, varargin)
29 width = 0.8;
30 group = true;
31
32 if (nargin < 3)
33 print_usage();
34 endif
35
36 if (nargin > 3 && isnumeric(varargin{2}))
37 x = varargin{1};
38 if (isvector(x))
39 x = x(:);
40 endif
41 y = varargin{2};
42 if (isvector(y))
43 y = y(:);
44 endif
45 if (size(x,1) != size(y,1))
46 y = varargin{1};
47 if (isvector(y))
48 y = y(:);
49 endif
50 x = [1:size(y,1)]';
51 idx = 2;
52 else
53 if (! isvector(x))
54 error ("%s: x must be a vector", func);
55 endif
56 idx = 3;
57 endif
58 else
59 y = varargin{1};
60 if (isvector(y))
61 y = y(:);
62 endif
63 x = [1:size(y,1)]';
64 idx = 2;
65 endif
66
67 newargs = {};
68 HaveLineSpec = false;
69 while (idx <= nargin -2)
70 if (isstr(varargin{idx}) && strcmp(varargin{idx},"grouped"))
71 group = true;
72 idx++;
73 elseif (isstr(varargin{idx}) && strcmp(varargin{idx},"stacked"))
74 group = false;
75 idx++;
76 else
77 if (!HaveLineSpec)
78 [dummy, valid] = __pltopt__ (func, varargin{idx}, false);
79 if (valid)
80 HaveLineSpec = true;
81 newargs = [newargs,varargin(idx++)];
82 continue;
83 endif
84 endif
85 if (isscalar(varargin{idx}))
86 width = varargin{idx++};
87 elseif (idx == nargin - 2)
88 newargs = [newargs,varargin(idx++)];
89 else
90 newargs = [newargs,varargin(idx:idx+1)];
91 idx += 2;
92 endif
93 endif
94 endwhile
95
96 xlen = size (x, 1);
97 ylen = size (y, 1);
98
99 if (xlen != ylen)
100 error ("%s: length of x and y must be equal", func)
101 endif
102 if (any (x(2:end) < x(1:end-1)))
103 error ("%s: x vector values must be in ascending order", func);
104 endif
105
106 ycols = size (y, 2);
107 if (group)
108 width = width / ycols;
109 endif
110
111 cutoff = (x(1:end-1) + x(2:end)) / 2;
112 delta_p = [(cutoff - x(1:end-1)); (x(end) - cutoff(end))] * width;
113 delta_m = [(cutoff(1) - x(1)); (x(2:end) - cutoff)] * width;
114 x1 = (x - delta_m)(:)';
115 x2 = (x + delta_p)(:)';
116 xb = repmat([x1; x1; x2; x2; NaN * ones(1,ylen)](:), 1, ycols);
117
118 if (group)
119 width = width / ycols;
120 offset = ((delta_p + delta_m) * [-(ycols - 1) / 2 : (ycols - 1) / 2]);
121 xb(1:5:5*ylen,:) += offset;
122 xb(2:5:5*ylen,:) += offset;
123 xb(3:5:5*ylen,:) += offset;
124 xb(4:5:5*ylen,:) += offset;
125 xb(5:5:5*ylen,:) += offset;
126 y0 = zeros (size (y));
127 y1 = y;
128 else
129 y1 = cumsum(y,2);
130 y0 = [zeros(ylen,1), y1(:,1:end-1)];
131 endif
132
133 yb = zeros (5*ylen, ycols);
134 yb(1:5:5*ylen,:) = y0;
135 yb(2:5:5*ylen,:) = y1;
136 yb(3:5:5*ylen,:) = y1;
137 yb(4:5:5*ylen,:) = y0;
138 yb(5:5:5*ylen,:) = NaN;
139
140 if (vertical)
141 if (nargout < 1)
142 plot (xb, yb, newargs{:});
143 elseif (nargout < 2)
144 varargout{1} = plot (xb, yb, newargs{:});
145 else
146 varargout{1} = xb;
147 varargout{2} = yb;
148 endif
149 else
150 if (nargout < 1)
151 plot (yb, xb, newargs{:});
152 elseif (nargout < 2)
153 varargout{1} = plot (yb, xb, newargs{:});
154 else
155 varargout{1} = yb;
156 varargout{2} = xb;
157 endif
158 endif
159
160 endfunction