Mercurial > octave
annotate scripts/plot/draw/stairs.m @ 32074:03fe0b635d2e
quiver/quiver3: Overhaul input processing, validation, and add BISTs.
* scripts/plot/draw/private/__quiver__.m: Overhaul numeric input validation.
Simplify input classification using numeric input count switch statements
and avoid quiver3 miscount due to scale factor. Add error messages for all
valid numeric input combinations including vector x,y,z and scale factor.
Move newplot command from quiver/quiver3 into __quiver__ after numeric input
validation. Add hax as an output argument to return any changes back to
calling function.
* scripts/plot/draw/quiver.m: Remove newplot call. Update __quiver__ call
to include hax as a return variable. Update docstring with note that line
style and name-value pairs can both be provided but linstyle must appear
first. Add BISTs to check standard inputs with single and multiple arrows,
arrowhead shape, vector and array inputs, proper treatment of scaling factor
"off", some simple input styles, and input validation BISTs to cover all
numeric input errors. Added known failing BIST for linestyle+pair
arrowhead showing when it should stay off (bug #64143).
* scripts/plot/draw/quiver3.m: Remove newplot call. Update __quiver__ call
to include hax as a return variable. Update docstring with note that line
style and name-value pairs can both be provided but linstyle must appear
first. Add BISTs to check standard inputs with single and multiple arrows,
vector and array inputs, and input validation BISTs to cover all numeric
input errors.
* etc/NEWS.9.md: Update quiver/quiver3 improvement description under General
Improvements.
author | Nicholas R. Jankowski <jankowski.nicholas@gmail.com> |
---|---|
date | Wed, 03 May 2023 22:52:33 -0400 |
parents | 597f3ee61a48 |
children | 2e484f9f1f18 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
31706
597f3ee61a48
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30875
diff
changeset
|
3 ## Copyright (C) 1993-2023 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
2313 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
2313 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22366
diff
changeset
|
13 ## (at your option) any later version. |
2313 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22366
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22366
diff
changeset
|
18 ## GNU General Public License for more details. |
2313 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24432
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
245 | 25 |
3368 | 26 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19700
diff
changeset
|
27 ## @deftypefn {} {} stairs (@var{y}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19700
diff
changeset
|
28 ## @deftypefnx {} {} stairs (@var{x}, @var{y}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19700
diff
changeset
|
29 ## @deftypefnx {} {} stairs (@dots{}, @var{style}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19700
diff
changeset
|
30 ## @deftypefnx {} {} stairs (@dots{}, @var{prop}, @var{val}, @dots{}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19700
diff
changeset
|
31 ## @deftypefnx {} {} stairs (@var{hax}, @dots{}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19700
diff
changeset
|
32 ## @deftypefnx {} {@var{h} =} stairs (@dots{}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19700
diff
changeset
|
33 ## @deftypefnx {} {[@var{xstep}, @var{ystep}] =} stairs (@dots{}) |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
34 ## Produce a stairstep plot. |
3426 | 35 ## |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
36 ## The arguments @var{x} and @var{y} may be vectors or matrices. |
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
37 ## If only one argument is given, it is taken as a vector of Y values |
24320
174a4426d441
stairs.m: Add example @code section showing what "indices of elements" means.
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
38 ## and the X coordinates are taken to be the indices of the elements |
174a4426d441
stairs.m: Add example @code section showing what "indices of elements" means.
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
39 ## (@code{@var{x} = 1:numel (@var{y})}). |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
40 ## |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
41 ## The style to use for the plot can be defined with a line style @var{style} |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17073
diff
changeset
|
42 ## of the same format as the @code{plot} command. |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
43 ## |
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
44 ## Multiple property/value pairs may be specified, but they must appear in |
29668
f17b1f0141ed
doc: Grammarcheck documentation ahead of 6.3 release.
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
45 ## pairs. The full list of properties is documented at |
28733
9342688e86b4
Updated property references for text and graphics functions (bug #50247)
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
27923
diff
changeset
|
46 ## @ref{Line Properties}. |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
47 ## |
24431
0c6cedafc71e
doc: Use 'axes' rather than 'axis' appropriately in docstrings.
Rik <rik@octave.org>
parents:
24320
diff
changeset
|
48 ## If the first argument @var{hax} is an axes handle, then plot into this axes, |
0c6cedafc71e
doc: Use 'axes' rather than 'axis' appropriately in docstrings.
Rik <rik@octave.org>
parents:
24320
diff
changeset
|
49 ## rather than the current axes returned by @code{gca}. |
3426 | 50 ## |
16814
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
16752
diff
changeset
|
51 ## If one output argument is requested, return a graphics handle to the |
16816
12005245b645
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16814
diff
changeset
|
52 ## created plot. If two output arguments are specified, the data are generated |
16814
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
16752
diff
changeset
|
53 ## but not plotted. For example, |
3426 | 54 ## |
3368 | 55 ## @example |
56 ## stairs (x, y); | |
57 ## @end example | |
3426 | 58 ## |
3368 | 59 ## @noindent |
2311 | 60 ## and |
3426 | 61 ## |
3368 | 62 ## @example |
6895 | 63 ## @group |
3368 | 64 ## [xs, ys] = stairs (x, y); |
65 ## plot (xs, ys); | |
6895 | 66 ## @end group |
3368 | 67 ## @end example |
3426 | 68 ## |
3368 | 69 ## @noindent |
2311 | 70 ## are equivalent. |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17073
diff
changeset
|
71 ## @seealso{bar, hist, plot, stem} |
3368 | 72 ## @end deftypefn |
4 | 73 |
30875
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
74 function [xstep, ystep] = stairs (varargin) |
4 | 75 |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
76 [hax, varargin, nargin] = __plt_get_axis_arg__ ("stairs", varargin{:}); |
4 | 77 |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
78 if (nargin < 1) |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
79 print_usage (); |
17211
87ba70043bfc
Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
80 endif |
17433 | 81 |
82 if (nargout < 2) | |
83 oldfig = []; | |
84 if (! isempty (hax)) | |
85 oldfig = get (0, "currentfigure"); | |
86 endif | |
87 unwind_protect | |
88 hax = newplot (hax); | |
30875
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
89 htmp = __stairs__ (true, varargin{:}); |
22366
837df5db5710
Make graphic functions visually compatible w/Matlab.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
90 |
837df5db5710
Make graphic functions visually compatible w/Matlab.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
91 if (! ishold ()) |
837df5db5710
Make graphic functions visually compatible w/Matlab.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
92 set (hax, "box", "on"); |
837df5db5710
Make graphic functions visually compatible w/Matlab.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
93 endif |
837df5db5710
Make graphic functions visually compatible w/Matlab.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
94 |
17433 | 95 unwind_protect_cleanup |
96 if (! isempty (oldfig)) | |
97 set (0, "currentfigure", oldfig); | |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
98 endif |
17433 | 99 end_unwind_protect |
100 if (nargout == 1) | |
30875
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
101 xstep = htmp; |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
102 endif |
17433 | 103 else |
30875
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
104 [~, xstep, ystep] = __stairs__ (false, varargin{:}); |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
105 endif |
17433 | 106 |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
107 endfunction |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
108 |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
109 function [h, xs, ys] = __stairs__ (doplot, varargin) |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
110 |
9809
965487e00282
stairs.m (__stairs__): correct nargin check; new demos
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
111 if (nargin == 2 || ischar (varargin{2})) |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
112 y = varargin{1}; |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
8056
diff
changeset
|
113 varargin(1) = []; |
19700
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
114 if (! isnumeric (y) || ndims (y) > 2) |
17433 | 115 error ("stairs: Y must be a numeric 2-D vector or matrix"); |
4 | 116 endif |
17433 | 117 if (isvector (y)) |
118 y = y(:); | |
119 endif | |
120 x = 1:rows (y); | |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
121 else |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
122 x = varargin{1}; |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
123 y = varargin{2}; |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
8056
diff
changeset
|
124 varargin(1:2) = []; |
19700
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
125 if (! isnumeric (x) || ! isnumeric (y) || ndims (x) > 2 || ndims (y) > 2) |
17433 | 126 error ("stairs: X and Y must be numeric 2-D vectors or matrices"); |
127 endif | |
6257 | 128 endif |
129 | |
130 vec_x = isvector (x); | |
131 if (vec_x) | |
132 x = x(:); | |
133 endif | |
134 | |
135 if (isvector (y)) | |
136 y = y(:); | |
19700
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
137 elseif (isnumeric (y) && vec_x) |
17433 | 138 x = repmat (x, [1, columns(y)]); |
6257 | 139 endif |
140 | |
17433 | 141 if (! size_equal (x, y)) |
142 error ("stairs: X and Y sizes must match"); | |
4 | 143 endif |
144 | |
17528
1da32463b540
stairs.m: Add missing definition of nr, nc.
Rik <rik@octave.org>
parents:
17527
diff
changeset
|
145 [nr, nc] = size (y); |
1da32463b540
stairs.m: Add missing definition of nr, nc.
Rik <rik@octave.org>
parents:
17527
diff
changeset
|
146 |
6257 | 147 len = 2*nr - 1; |
148 | |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
149 xs = ys = zeros (len, nc); |
6257 | 150 |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
151 xs(1,:) = x(1,:); |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
152 ys(1,:) = y(1,:); |
6257 | 153 |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
154 xtmp = x(2:nr,:); |
6257 | 155 ridx = 2:2:len-1; |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
156 xs(ridx,:) = xtmp; |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
157 ys(ridx,:) = y(1:nr-1,:); |
6257 | 158 |
159 ridx = 3:2:len; | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
160 xs(ridx,:) = xtmp; |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
161 ys(ridx,:) = y(2:nr,:); |
6257 | 162 |
8243
ec4d9d657b17
Treat line style argument in stairs
David Bateman <dbateman@free.fr>
parents:
8079
diff
changeset
|
163 have_line_spec = false; |
17433 | 164 for i = 1:2:numel (varargin) |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
165 arg = varargin{i}; |
17462
177147bf7b55
Overhaul use of __pltopt__.m to correctly check for cellstr, not just cell.
Rik <rik@octave.org>
parents:
17433
diff
changeset
|
166 if (ischar (arg) || iscellstr (arg)) |
8243
ec4d9d657b17
Treat line style argument in stairs
David Bateman <dbateman@free.fr>
parents:
8079
diff
changeset
|
167 [linespec, valid] = __pltopt__ ("stairs", arg, false); |
ec4d9d657b17
Treat line style argument in stairs
David Bateman <dbateman@free.fr>
parents:
8079
diff
changeset
|
168 if (valid) |
10549 | 169 have_line_spec = true; |
170 varargin(i) = []; | |
171 break; | |
8243
ec4d9d657b17
Treat line style argument in stairs
David Bateman <dbateman@free.fr>
parents:
8079
diff
changeset
|
172 endif |
ec4d9d657b17
Treat line style argument in stairs
David Bateman <dbateman@free.fr>
parents:
8079
diff
changeset
|
173 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
174 endfor |
8243
ec4d9d657b17
Treat line style argument in stairs
David Bateman <dbateman@free.fr>
parents:
8079
diff
changeset
|
175 |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
176 if (doplot) |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
177 h = []; |
17126
26589abbc78d
Don't pass axis handle unnecessarily from high level to low level plot functions.
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
178 hold_state = get (gca (), "nextplot"); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
179 unwind_protect |
14872
c2dbdeaa25df
maint: use rows() and columns() to clarify m-files.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
180 for i = 1 : columns (y) |
17433 | 181 |
182 if (have_line_spec) | |
183 lc = linespec.color; | |
184 if (isempty (lc)) | |
185 lc = __next_line_color__ (); | |
186 endif | |
187 ls = linespec.linestyle; | |
188 if (isempty (ls)) | |
189 ls = "-"; | |
190 endif | |
191 mk = linespec.marker; | |
192 if (isempty (mk)) | |
193 mk = "none"; | |
194 endif | |
195 else | |
196 lc = __next_line_color__ (); | |
197 ls = "-"; | |
198 mk = "none"; | |
199 endif | |
200 | |
201 ## Must occur after __next_line_color__ in order to work correctly. | |
10549 | 202 hg = hggroup (); |
203 h = [h; hg]; | |
204 args = __add_datasource__ ("stairs", hg, {"x", "y"}, varargin{:}); | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
205 |
10549 | 206 addproperty ("xdata", hg, "data", x(:,i).'); |
207 addproperty ("ydata", hg, "data", y(:,i).'); | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
208 |
10549 | 209 addlistener (hg, "xdata", @update_data); |
210 addlistener (hg, "ydata", @update_data); | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
211 |
17433 | 212 htmp = line (xs(:,i).', ys(:,i).', "color", lc, "linestyle", ls, |
213 "marker", mk, "parent", hg); | |
8075
a028a5960e18
Fix for hold with no figures/axes. Set prop/val pairs to hggroups rather than underlying objects. Fix for equality test in array_property
David Bateman <dbateman@free.fr>
parents:
8070
diff
changeset
|
214 |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
215 addproperty ("color", hg, "linecolor", get (htmp, "color")); |
17433 | 216 addproperty ("linestyle", hg, "linelinestyle", get (htmp, "linestyle")); |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
217 addproperty ("linewidth", hg, "linelinewidth", get (htmp, "linewidth")); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
218 |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
219 addproperty ("marker", hg, "linemarker", get (htmp, "marker")); |
17433 | 220 addproperty ("markeredgecolor", hg, "linemarkeredgecolor", |
221 get (htmp, "markeredgecolor")); | |
10549 | 222 addproperty ("markerfacecolor", hg, "linemarkerfacecolor", |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
223 get (htmp, "markerfacecolor")); |
10549 | 224 addproperty ("markersize", hg, "linemarkersize", |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
225 get (htmp, "markersize")); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
226 |
10549 | 227 addlistener (hg, "color", @update_props); |
17433 | 228 addlistener (hg, "linestyle", @update_props); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
229 addlistener (hg, "linewidth", @update_props); |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
230 addlistener (hg, "marker", @update_props); |
17433 | 231 addlistener (hg, "markeredgecolor", @update_props); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
232 addlistener (hg, "markerfacecolor", @update_props); |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
233 addlistener (hg, "markersize", @update_props); |
8075
a028a5960e18
Fix for hold with no figures/axes. Set prop/val pairs to hggroups rather than underlying objects. Fix for equality test in array_property
David Bateman <dbateman@free.fr>
parents:
8070
diff
changeset
|
234 |
17527
76614e624818
Add "HitTestArea" property to certain hggroups for Matlab compatibility
Rik <rik@octave.org>
parents:
17462
diff
changeset
|
235 ## Matlab property, although Octave does not implement it. |
76614e624818
Add "HitTestArea" property to certain hggroups for Matlab compatibility
Rik <rik@octave.org>
parents:
17462
diff
changeset
|
236 addproperty ("hittestarea", hg, "radio", "on|{off}", "off"); |
76614e624818
Add "HitTestArea" property to certain hggroups for Matlab compatibility
Rik <rik@octave.org>
parents:
17462
diff
changeset
|
237 |
10549 | 238 if (! isempty (args)) |
239 set (hg, args{:}); | |
240 endif | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
241 endfor |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
242 unwind_protect_cleanup |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
243 set (gca (), "nextplot", hold_state); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
244 end_unwind_protect |
736 | 245 else |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
246 h = 0; |
4 | 247 endif |
248 | |
249 endfunction | |
7245 | 250 |
17433 | 251 function update_props (h, ~) |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
252 set (get (h, "children"), |
17572
7bb76a22cde1
maint: Split scripts/plot directory into 4 pieces.
Rik <rik@octave.org>
parents:
17528
diff
changeset
|
253 {"color", "linestyle", "linewidth", "marker", ... |
7bb76a22cde1
maint: Split scripts/plot directory into 4 pieces.
Rik <rik@octave.org>
parents:
17528
diff
changeset
|
254 "markeredgecolor", "markerfacecolor", "markersize"}, |
7bb76a22cde1
maint: Split scripts/plot directory into 4 pieces.
Rik <rik@octave.org>
parents:
17528
diff
changeset
|
255 get (h, {"color", "linestyle", "linewidth", "marker", ... |
7bb76a22cde1
maint: Split scripts/plot directory into 4 pieces.
Rik <rik@octave.org>
parents:
17528
diff
changeset
|
256 "markeredgecolor", "markerfacecolor", "markersize"})); |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
257 endfunction |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
258 |
17433 | 259 function update_data (h, ~) |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
260 |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
261 x = get (h, "xdata"); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
262 y = get (h, "ydata"); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
263 |
16752
d6b666e8449c
Update copies consistent subset of {x,y,z}data to children of the stairs hggoup.
Ben Abbott <bpabbott@mac.com>
parents:
14872
diff
changeset
|
264 sz = min ([size(x); size(y)]); |
d6b666e8449c
Update copies consistent subset of {x,y,z}data to children of the stairs hggoup.
Ben Abbott <bpabbott@mac.com>
parents:
14872
diff
changeset
|
265 x = x(1:sz(1), 1:sz(2)); |
d6b666e8449c
Update copies consistent subset of {x,y,z}data to children of the stairs hggoup.
Ben Abbott <bpabbott@mac.com>
parents:
14872
diff
changeset
|
266 y = y(1:sz(1), 1:sz(2)); |
d6b666e8449c
Update copies consistent subset of {x,y,z}data to children of the stairs hggoup.
Ben Abbott <bpabbott@mac.com>
parents:
14872
diff
changeset
|
267 |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
268 nr = length (x); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
269 len = 2 * nr - 1; |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
270 xs = ys = zeros (1, len); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
271 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
272 xs(1) = x(1); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
273 ys(1) = y(1); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
274 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
275 xtmp = x(2:nr); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
276 ridx = 2:2:len-1; |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
277 xs(ridx) = xtmp; |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
278 ys(ridx) = y(1:nr-1); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
279 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
280 ridx = 3:2:len; |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
281 xs(ridx) = xtmp; |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
282 ys(ridx) = y(2:nr); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
283 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
284 set (get (h, "children"), "xdata", xs, "ydata", ys); |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
285 |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
286 endfunction |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
287 |
17433 | 288 |
289 %!demo | |
290 %! clf; | |
291 %! rand_1x10_data1 = [0.073, 0.455, 0.837, 0.124, 0.426, 0.781, 0.004, 0.024, 0.519, 0.698]; | |
292 %! y = rand_1x10_data1; | |
293 %! stairs (y); | |
294 %! title ('stairs() plot of y-data'); | |
295 | |
296 %!demo | |
297 %! clf; | |
298 %! x = 1:10; | |
299 %! rand_1x10_data2 = [0.014, 0.460, 0.622, 0.394, 0.531, 0.378, 0.466, 0.788, 0.342, 0.893]; | |
300 %! y = rand_1x10_data2; | |
301 %! [xs, ys] = stairs (x, y); | |
302 %! plot (xs, ys); | |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
21758
diff
changeset
|
303 %! title ("plot() of stairs() generated data"); |
17433 | 304 |
305 %!demo | |
306 %! clf; | |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
21758
diff
changeset
|
307 %! stairs (1:9, "-o"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
21758
diff
changeset
|
308 %! title ("stairs() plot with linespec to modify marker"); |
17433 | 309 |
310 %!demo | |
311 %! clf; | |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
21758
diff
changeset
|
312 %! stairs (9:-1:1, "marker", "s", "markersize", 10, "markerfacecolor", "m"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
21758
diff
changeset
|
313 %! title ("stairs() plot with prop/val pairs to modify appearance"); |
17433 | 314 |
315 %!demo | |
316 %! clf; | |
317 %! N = 11; | |
318 %! x = 0:(N-1); | |
319 %! y = rand (1, N); | |
320 %! hs = stairs (x(1), y(1)); | |
321 %! axis ([1, N-1 0, 1]); | |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
21758
diff
changeset
|
322 %! title ("stairs plot data modified through handle"); |
17433 | 323 %! for k = 2:N |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
21758
diff
changeset
|
324 %! set (hs, "xdata", x(1:k), "ydata", y(1:k)); |
17433 | 325 %! drawnow (); |
326 %! pause (0.2); | |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
21758
diff
changeset
|
327 %! endfor |
17433 | 328 |
329 ## Invisible figure used for tests | |
330 %!shared hf, hax | |
331 %! hf = figure ("visible", "off"); | |
28892
3cac3ceb9629
maint: Use coding style with parentheses after function name to distinguish from a variable.
Rik <rik@octave.org>
parents:
28753
diff
changeset
|
332 %! hax = axes (); |
17433 | 333 |
28896
90fea9cc9caa
test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents:
28892
diff
changeset
|
334 %!error <Invalid call> stairs () |
17433 | 335 %!error <Y must be a numeric 2-D vector> stairs (hax, {1}) |
336 %!error <Y must be a numeric 2-D vector> stairs (ones (2,2,2)) | |
337 %!error <X and Y must be numeric 2-D vector> stairs ({1}, 1) | |
338 %!error <X and Y must be numeric 2-D vector> stairs (1, {1}) | |
339 %!error <X and Y must be numeric 2-D vector> stairs (ones (2,2,2), 1) | |
340 %!error <X and Y must be numeric 2-D vector> stairs (1, ones (2,2,2)) | |
341 %!error <X and Y sizes must match> stairs (1:2, 1:3) | |
342 | |
343 ## Close figure used for testing | |
344 %!test | |
345 %! close (hf); |