Mercurial > hg > octave-lyh
annotate scripts/plot/__bar__.m @ 8232:c6e9ff62c64a
Fix subplot for column vector of children in figure
author | David Bateman <dbateman@free.fr> |
---|---|
date | Thu, 16 Oct 2008 16:23:14 -0400 |
parents | 73d6b71788c0 |
children | e07e93c04080 |
rev | line source |
---|---|
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 |
7215 | 25 [h, varargin] = __plt_get_axis_arg__ ((nargout > 1), func, varargin{:}); |
7189 | 26 |
7148 | 27 ## Slightly smaller than 0.8 to avoid clipping issue in gnuplot 4.0 |
28 width = 0.8 - 10 * eps; | |
6540 | 29 group = true; |
7325 | 30 bv = 0; |
6540 | 31 |
7215 | 32 if (nargin < 3) |
6886 | 33 print_usage (); |
6540 | 34 endif |
35 | |
7215 | 36 if (nargin > 3 && isnumeric (varargin{2})) |
6540 | 37 x = varargin{1}; |
6886 | 38 if (isvector (x)) |
6540 | 39 x = x(:); |
40 endif | |
41 y = varargin{2}; | |
6886 | 42 if (isvector (y)) |
6540 | 43 y = y(:); |
44 endif | |
6886 | 45 if (size (x, 1) != size (y, 1)) |
6540 | 46 y = varargin{1}; |
6886 | 47 if (isvector (y)) |
6540 | 48 y = y(:); |
49 endif | |
50 x = [1:size(y,1)]'; | |
51 idx = 2; | |
52 else | |
6886 | 53 if (! isvector (x)) |
6540 | 54 error ("%s: x must be a vector", func); |
55 endif | |
56 idx = 3; | |
57 endif | |
58 else | |
59 y = varargin{1}; | |
6886 | 60 if (isvector (y)) |
6540 | 61 y = y(:); |
62 endif | |
63 x = [1:size(y,1)]'; | |
64 idx = 2; | |
65 endif | |
66 | |
67 newargs = {}; | |
6886 | 68 have_line_spec = false; |
7215 | 69 while (idx <= nargin - 2) |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
8056
diff
changeset
|
70 if (ischar (varargin{idx}) && strcmpi (varargin{idx}, "grouped")) |
6540 | 71 group = true; |
72 idx++; | |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
8056
diff
changeset
|
73 elseif (ischar (varargin{idx}) && strcmpi (varargin{idx}, "stacked")) |
6540 | 74 group = false; |
75 idx++; | |
76 else | |
7768
a2d9f325b65a
Use isschar instead of deprecated isstr
Rafael Laboissiere <rafael@debian.org>
parents:
7325
diff
changeset
|
77 if ((ischar (varargin{idx}) || iscell (varargin{idx})) |
6886 | 78 && ! have_line_spec) |
6885 | 79 [linespec, valid] = __pltopt__ (func, varargin{idx}, false); |
6540 | 80 if (valid) |
6886 | 81 have_line_spec = true; |
6885 | 82 newargs = [{linespec.color}, newargs]; |
83 idx++; | |
6540 | 84 continue; |
85 endif | |
86 endif | |
87 if (isscalar(varargin{idx})) | |
88 width = varargin{idx++}; | |
7215 | 89 elseif (idx == nargin - 2) |
6540 | 90 newargs = [newargs,varargin(idx++)]; |
8190
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
8056
diff
changeset
|
91 elseif (ischar (varargin{idx}) |
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
8056
diff
changeset
|
92 && strcmpi (varargin{idx}, "basevalue") |
73d6b71788c0
use case-insensitive comparison for graphics properties; misc style fixes
John W. Eaton <jwe@octave.org>
parents:
8056
diff
changeset
|
93 && isscalar (varargin{idx+1})) |
7325 | 94 bv = varargin{idx+1}; |
95 idx += 2; | |
6540 | 96 else |
97 newargs = [newargs,varargin(idx:idx+1)]; | |
98 idx += 2; | |
99 endif | |
100 endif | |
101 endwhile | |
102 | |
103 xlen = size (x, 1); | |
104 ylen = size (y, 1); | |
105 | |
106 if (xlen != ylen) | |
107 error ("%s: length of x and y must be equal", func) | |
108 endif | |
109 if (any (x(2:end) < x(1:end-1))) | |
110 error ("%s: x vector values must be in ascending order", func); | |
111 endif | |
112 | |
113 ycols = size (y, 2); | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
114 cutoff = min (diff (double(x))) / 2; |
6540 | 115 if (group) |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
116 delta_p = delta_m = repmat (cutoff * width / ycols, size (x)); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
117 else |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7768
diff
changeset
|
118 delta_p = delta_m = repmat (cutoff * width, size (x)); |
6540 | 119 endif |
120 x1 = (x - delta_m)(:)'; | |
121 x2 = (x + delta_p)(:)'; | |
6886 | 122 xb = repmat ([x1; x1; x2; x2](:), 1, ycols); |
6540 | 123 |
124 if (group) | |
125 offset = ((delta_p + delta_m) * [-(ycols - 1) / 2 : (ycols - 1) / 2]); | |
6885 | 126 xb(1:4:4*ylen,:) += offset; |
127 xb(2:4:4*ylen,:) += offset; | |
128 xb(3:4:4*ylen,:) += offset; | |
129 xb(4:4:4*ylen,:) += offset; | |
7325 | 130 y0 = zeros (size (y)) + bv; |
6540 | 131 y1 = y; |
132 else | |
133 y1 = cumsum(y,2); | |
7325 | 134 y0 = [zeros(ylen,1)+bv, y1(:,1:end-1)]; |
6540 | 135 endif |
136 | |
6885 | 137 yb = zeros (4*ylen, ycols); |
138 yb(1:4:4*ylen,:) = y0; | |
139 yb(2:4:4*ylen,:) = y1; | |
140 yb(3:4:4*ylen,:) = y1; | |
141 yb(4:4:4*ylen,:) = y0; | |
142 | |
7148 | 143 xb = reshape (xb, [4, numel(xb) / 4 / ycols, ycols]); |
144 yb = reshape (yb, [4, numel(yb) / 4 / ycols, ycols]); | |
6885 | 145 |
7189 | 146 if (nargout < 2) |
7215 | 147 oldh = gca (); |
148 unwind_protect | |
149 axes (h); | |
150 newplot (); | |
151 | |
152 tmp = __bars__ (h, vertical, x, y, xb, yb, width, group, | |
7325 | 153 have_line_spec, bv, newargs{:}); |
7215 | 154 if (nargout == 1) |
155 varargout{1} = tmp; | |
156 endif | |
157 unwind_protect_cleanup | |
158 axes (oldh); | |
159 end_unwind_protect | |
7189 | 160 else |
161 if (vertical) | |
6540 | 162 varargout{1} = xb; |
163 varargout{2} = yb; | |
164 else | |
165 varargout{1} = yb; | |
166 varargout{2} = xb; | |
167 endif | |
6886 | 168 endif |
7191 | 169 |
6540 | 170 endfunction |