7017
|
1 ## Copyright (C) 1996, 1997, 2007 John W. Eaton |
6540
|
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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
6540
|
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 |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
6540
|
18 |
6895
|
19 ## Undocumented internal function. |
6540
|
20 |
|
21 ## Author: jwe |
|
22 |
|
23 function varargout = __bar__ (vertical, func, varargin) |
6886
|
24 |
7148
|
25 ## Slightly smaller than 0.8 to avoid clipping issue in gnuplot 4.0 |
|
26 width = 0.8 - 10 * eps; |
6540
|
27 group = true; |
|
28 |
|
29 if (nargin < 3) |
6886
|
30 print_usage (); |
6540
|
31 endif |
|
32 |
6886
|
33 if (nargin > 3 && isnumeric (varargin{2})) |
6540
|
34 x = varargin{1}; |
6886
|
35 if (isvector (x)) |
6540
|
36 x = x(:); |
|
37 endif |
|
38 y = varargin{2}; |
6886
|
39 if (isvector (y)) |
6540
|
40 y = y(:); |
|
41 endif |
6886
|
42 if (size (x, 1) != size (y, 1)) |
6540
|
43 y = varargin{1}; |
6886
|
44 if (isvector (y)) |
6540
|
45 y = y(:); |
|
46 endif |
|
47 x = [1:size(y,1)]'; |
|
48 idx = 2; |
|
49 else |
6886
|
50 if (! isvector (x)) |
6540
|
51 error ("%s: x must be a vector", func); |
|
52 endif |
|
53 idx = 3; |
|
54 endif |
|
55 else |
|
56 y = varargin{1}; |
6886
|
57 if (isvector (y)) |
6540
|
58 y = y(:); |
|
59 endif |
|
60 x = [1:size(y,1)]'; |
|
61 idx = 2; |
|
62 endif |
|
63 |
|
64 newargs = {}; |
6886
|
65 have_line_spec = false; |
6540
|
66 while (idx <= nargin -2) |
6886
|
67 if (isstr (varargin{idx}) && strcmp (varargin{idx}, "grouped")) |
6540
|
68 group = true; |
|
69 idx++; |
6886
|
70 elseif (isstr (varargin{idx}) && strcmp (varargin{idx}, "stacked")) |
6540
|
71 group = false; |
|
72 idx++; |
|
73 else |
6886
|
74 if ((isstr (varargin{idx}) || iscell (varargin{idx})) |
|
75 && ! have_line_spec) |
6885
|
76 [linespec, valid] = __pltopt__ (func, varargin{idx}, false); |
6540
|
77 if (valid) |
6886
|
78 have_line_spec = true; |
6885
|
79 newargs = [{linespec.color}, newargs]; |
|
80 idx++; |
6540
|
81 continue; |
|
82 endif |
|
83 endif |
|
84 if (isscalar(varargin{idx})) |
|
85 width = varargin{idx++}; |
|
86 elseif (idx == nargin - 2) |
|
87 newargs = [newargs,varargin(idx++)]; |
|
88 else |
|
89 newargs = [newargs,varargin(idx:idx+1)]; |
|
90 idx += 2; |
|
91 endif |
|
92 endif |
|
93 endwhile |
|
94 |
|
95 xlen = size (x, 1); |
|
96 ylen = size (y, 1); |
|
97 |
|
98 if (xlen != ylen) |
|
99 error ("%s: length of x and y must be equal", func) |
|
100 endif |
|
101 if (any (x(2:end) < x(1:end-1))) |
|
102 error ("%s: x vector values must be in ascending order", func); |
|
103 endif |
|
104 |
|
105 ycols = size (y, 2); |
|
106 if (group) |
|
107 width = width / ycols; |
|
108 endif |
|
109 |
|
110 cutoff = (x(1:end-1) + x(2:end)) / 2; |
|
111 delta_p = [(cutoff - x(1:end-1)); (x(end) - cutoff(end))] * width; |
|
112 delta_m = [(cutoff(1) - x(1)); (x(2:end) - cutoff)] * width; |
|
113 x1 = (x - delta_m)(:)'; |
|
114 x2 = (x + delta_p)(:)'; |
6886
|
115 xb = repmat ([x1; x1; x2; x2](:), 1, ycols); |
6540
|
116 |
|
117 if (group) |
|
118 width = width / ycols; |
|
119 offset = ((delta_p + delta_m) * [-(ycols - 1) / 2 : (ycols - 1) / 2]); |
6885
|
120 xb(1:4:4*ylen,:) += offset; |
|
121 xb(2:4:4*ylen,:) += offset; |
|
122 xb(3:4:4*ylen,:) += offset; |
|
123 xb(4:4:4*ylen,:) += offset; |
6540
|
124 y0 = zeros (size (y)); |
|
125 y1 = y; |
|
126 else |
|
127 y1 = cumsum(y,2); |
|
128 y0 = [zeros(ylen,1), y1(:,1:end-1)]; |
|
129 endif |
|
130 |
6885
|
131 yb = zeros (4*ylen, ycols); |
|
132 yb(1:4:4*ylen,:) = y0; |
|
133 yb(2:4:4*ylen,:) = y1; |
|
134 yb(3:4:4*ylen,:) = y1; |
|
135 yb(4:4:4*ylen,:) = y0; |
|
136 |
7148
|
137 xb = reshape (xb, [4, numel(xb) / 4 / ycols, ycols]); |
|
138 yb = reshape (yb, [4, numel(yb) / 4 / ycols, ycols]); |
6885
|
139 |
7148
|
140 color = [1, 0, 0; 0, 1, 0; 0, 0, 1; 1, 1, 0; 1, 0, 1; 0, 1, 1]; |
6540
|
141 if (vertical) |
7148
|
142 if (nargout < 2) |
7039
|
143 newplot (); |
7148
|
144 tmp = []; |
|
145 for i = 1 : ycols |
|
146 if (! have_line_spec) |
|
147 tmp = [tmp; patch(xb(:,:,i), yb(:,:,i), color(i,:), newargs {:})]; |
|
148 else |
|
149 tmp = [tmp; patch(xb(:,:,i), yb(:,:,i), newargs {:})]; |
|
150 endif |
|
151 endfor |
|
152 if (nargout == 1) |
|
153 varargout{1} = tmp; |
|
154 endif |
6540
|
155 else |
|
156 varargout{1} = xb; |
|
157 varargout{2} = yb; |
|
158 endif |
|
159 else |
7148
|
160 if (nargout < 2) |
7039
|
161 newplot (); |
7148
|
162 tmp = []; |
|
163 for i = 1 : ycols |
|
164 if (! have_line_spec) |
|
165 tmp = [tmp; patch(yb(:,:,i), xb(:,:,i), color(i,:), newargs {:})]; |
|
166 else |
|
167 tmp = [tmp; patch(yb(:,:,i), xb(:,:,i), newargs {:})]; |
|
168 endif |
|
169 endfor |
|
170 if (nargout == 1) |
|
171 varargout{1} = tmp; |
|
172 endif |
6540
|
173 else |
|
174 varargout{1} = yb; |
|
175 varargout{2} = xb; |
|
176 endif |
6886
|
177 endif |
6540
|
178 |
|
179 endfunction |