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