Mercurial > hg > octave-lyh
annotate scripts/plot/stairs.m @ 17535:c12c688a35ed default tip lyh
Fix warnings
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Fri, 27 Sep 2013 17:43:27 +0800 |
parents | 177147bf7b55 |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14092
diff
changeset
|
1 ## Copyright (C) 1993-2012 John W. Eaton |
2313 | 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. | |
2313 | 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/>. | |
245 | 18 |
3368 | 19 ## -*- texinfo -*- |
10736
14af8004945d
stairs.m: Add additional calling forms to documentation
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
20 ## @deftypefn {Function File} {} stairs (@var{y}) |
14af8004945d
stairs.m: Add additional calling forms to documentation
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
21 ## @deftypefnx {Function File} {} stairs (@var{x}, @var{y}) |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
22 ## @deftypefnx {Function File} {} stairs (@dots{}, @var{style}) |
17126
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17073
diff
changeset
|
23 ## @deftypefnx {Function File} {} stairs (@dots{}, @var{prop}, @var{val}, @dots{}) |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
24 ## @deftypefnx {Function File} {} stairs (@var{hax}, @dots{}) |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
25 ## @deftypefnx {Function File} {@var{h} =} stairs (@dots{}) |
10736
14af8004945d
stairs.m: Add additional calling forms to documentation
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
26 ## @deftypefnx {Function File} {[@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
|
27 ## Produce a stairstep plot. |
3426 | 28 ## |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
29 ## 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
|
30 ## If only one argument is given, it is taken as a vector of Y values |
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
31 ## and the X coordinates are taken to be the indices of the elements. |
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
32 ## |
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
33 ## The style to use for the plot can be defined with a line style @var{style} |
17126
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17073
diff
changeset
|
34 ## 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
|
35 ## |
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
36 ## Multiple property/value pairs may be specified, but they must appear in |
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
37 ## pairs. |
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
38 ## |
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
39 ## If the first argument @var{hax} is an axis handle, then plot into this axis, |
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
40 ## rather than the current axis handle returned by @code{gca}. |
3426 | 41 ## |
16814
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
16752
diff
changeset
|
42 ## 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
|
43 ## 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
|
44 ## but not plotted. For example, |
3426 | 45 ## |
3368 | 46 ## @example |
47 ## stairs (x, y); | |
48 ## @end example | |
3426 | 49 ## |
3368 | 50 ## @noindent |
2311 | 51 ## and |
3426 | 52 ## |
3368 | 53 ## @example |
6895 | 54 ## @group |
3368 | 55 ## [xs, ys] = stairs (x, y); |
56 ## plot (xs, ys); | |
6895 | 57 ## @end group |
3368 | 58 ## @end example |
3426 | 59 ## |
3368 | 60 ## @noindent |
2311 | 61 ## are equivalent. |
17126
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17073
diff
changeset
|
62 ## @seealso{bar, hist, plot, stem} |
3368 | 63 ## @end deftypefn |
4 | 64 |
2314 | 65 ## Author: jwe |
66 | |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
67 function [xs, ys] = stairs (varargin) |
4 | 68 |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
69 [hax, varargin, nargin] = __plt_get_axis_arg__ ("stairs", varargin{:}); |
4 | 70 |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
71 if (nargin < 1) |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
72 print_usage (); |
17219
87ba70043bfc
Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents:
17130
diff
changeset
|
73 endif |
17441 | 74 |
75 if (nargout < 2) | |
76 oldfig = []; | |
77 if (! isempty (hax)) | |
78 oldfig = get (0, "currentfigure"); | |
79 endif | |
80 unwind_protect | |
81 hax = newplot (hax); | |
82 [htmp, xxs, yys] = __stairs__ (true, varargin{:}); | |
83 unwind_protect_cleanup | |
84 if (! isempty (oldfig)) | |
85 set (0, "currentfigure", oldfig); | |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
86 endif |
17441 | 87 end_unwind_protect |
88 if (nargout == 1) | |
89 xs = htmp; | |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
90 endif |
17441 | 91 else |
92 [~, xs, ys] = __stairs__ (false, varargin{:}); | |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
93 endif |
17441 | 94 |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
95 endfunction |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
96 |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
97 function [h, xs, ys] = __stairs__ (doplot, varargin) |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
98 |
9809
965487e00282
stairs.m (__stairs__): correct nargin check; new demos
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
99 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
|
100 y = varargin{1}; |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
8056
diff
changeset
|
101 varargin(1) = []; |
17441 | 102 if (! ismatrix (y) || ndims (y) > 2) |
103 error ("stairs: Y must be a numeric 2-D vector or matrix"); | |
4 | 104 endif |
17441 | 105 if (isvector (y)) |
106 y = y(:); | |
107 endif | |
108 x = 1:rows (y); | |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
109 else |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
110 x = varargin{1}; |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
111 y = varargin{2}; |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
8056
diff
changeset
|
112 varargin(1:2) = []; |
17441 | 113 if (! ismatrix (x) || ! ismatrix (y) || ndims (x) > 2 || ndims (y) > 2) |
114 error ("stairs: X and Y must be numeric 2-D vectors or matrices"); | |
115 endif | |
6257 | 116 endif |
117 | |
118 vec_x = isvector (x); | |
119 if (vec_x) | |
120 x = x(:); | |
121 endif | |
122 | |
123 if (isvector (y)) | |
124 y = y(:); | |
17441 | 125 elseif (ismatrix (y) && vec_x) |
126 x = repmat (x, [1, columns(y)]); | |
6257 | 127 endif |
128 | |
17441 | 129 if (! size_equal (x, y)) |
130 error ("stairs: X and Y sizes must match"); | |
4 | 131 endif |
132 | |
6257 | 133 len = 2*nr - 1; |
134 | |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
135 xs = ys = zeros (len, nc); |
6257 | 136 |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
137 xs(1,:) = x(1,:); |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
138 ys(1,:) = y(1,:); |
6257 | 139 |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
140 xtmp = x(2:nr,:); |
6257 | 141 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
|
142 xs(ridx,:) = xtmp; |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
143 ys(ridx,:) = y(1:nr-1,:); |
6257 | 144 |
145 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
|
146 xs(ridx,:) = xtmp; |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
147 ys(ridx,:) = y(2:nr,:); |
6257 | 148 |
8243
ec4d9d657b17
Treat line style argument in stairs
David Bateman <dbateman@free.fr>
parents:
8079
diff
changeset
|
149 have_line_spec = false; |
17441 | 150 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
|
151 arg = varargin{i}; |
17473
177147bf7b55
Overhaul use of __pltopt__.m to correctly check for cellstr, not just cell.
Rik <rik@octave.org>
parents:
17441
diff
changeset
|
152 if (ischar (arg) || iscellstr (arg)) |
8243
ec4d9d657b17
Treat line style argument in stairs
David Bateman <dbateman@free.fr>
parents:
8079
diff
changeset
|
153 [linespec, valid] = __pltopt__ ("stairs", arg, false); |
ec4d9d657b17
Treat line style argument in stairs
David Bateman <dbateman@free.fr>
parents:
8079
diff
changeset
|
154 if (valid) |
10549 | 155 have_line_spec = true; |
156 varargin(i) = []; | |
157 break; | |
8243
ec4d9d657b17
Treat line style argument in stairs
David Bateman <dbateman@free.fr>
parents:
8079
diff
changeset
|
158 endif |
ec4d9d657b17
Treat line style argument in stairs
David Bateman <dbateman@free.fr>
parents:
8079
diff
changeset
|
159 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
160 endfor |
8243
ec4d9d657b17
Treat line style argument in stairs
David Bateman <dbateman@free.fr>
parents:
8079
diff
changeset
|
161 |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
162 if (doplot) |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
163 h = []; |
17130
26589abbc78d
Don't pass axis handle unnecessarily from high level to low level plot functions.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
164 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
|
165 unwind_protect |
14872
c2dbdeaa25df
maint: use rows() and columns() to clarify m-files.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
166 for i = 1 : columns (y) |
17441 | 167 |
168 if (have_line_spec) | |
169 lc = linespec.color; | |
170 if (isempty (lc)) | |
171 lc = __next_line_color__ (); | |
172 endif | |
173 ls = linespec.linestyle; | |
174 if (isempty (ls)) | |
175 ls = "-"; | |
176 endif | |
177 mk = linespec.marker; | |
178 if (isempty (mk)) | |
179 mk = "none"; | |
180 endif | |
181 else | |
182 lc = __next_line_color__ (); | |
183 ls = "-"; | |
184 mk = "none"; | |
185 endif | |
186 | |
187 ## Must occur after __next_line_color__ in order to work correctly. | |
10549 | 188 hg = hggroup (); |
189 h = [h; hg]; | |
190 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
|
191 |
10549 | 192 addproperty ("xdata", hg, "data", x(:,i).'); |
193 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
|
194 |
10549 | 195 addlistener (hg, "xdata", @update_data); |
196 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
|
197 |
17441 | 198 htmp = line (xs(:,i).', ys(:,i).', "color", lc, "linestyle", ls, |
199 "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
|
200 |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
201 addproperty ("color", hg, "linecolor", get (htmp, "color")); |
17441 | 202 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
|
203 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
|
204 |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
205 addproperty ("marker", hg, "linemarker", get (htmp, "marker")); |
17441 | 206 addproperty ("markeredgecolor", hg, "linemarkeredgecolor", |
207 get (htmp, "markeredgecolor")); | |
10549 | 208 addproperty ("markerfacecolor", hg, "linemarkerfacecolor", |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
209 get (htmp, "markerfacecolor")); |
10549 | 210 addproperty ("markersize", hg, "linemarkersize", |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
211 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
|
212 |
10549 | 213 addlistener (hg, "color", @update_props); |
17441 | 214 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
|
215 addlistener (hg, "linewidth", @update_props); |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
216 addlistener (hg, "marker", @update_props); |
17441 | 217 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
|
218 addlistener (hg, "markerfacecolor", @update_props); |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
219 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
|
220 |
10549 | 221 if (! isempty (args)) |
222 set (hg, args{:}); | |
223 endif | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
224 endfor |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
225 unwind_protect_cleanup |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
226 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
|
227 end_unwind_protect |
736 | 228 else |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
229 h = 0; |
4 | 230 endif |
231 | |
232 endfunction | |
7245 | 233 |
17441 | 234 function update_props (h, ~) |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
235 set (get (h, "children"), |
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
236 "color", get (h, "color"), |
17441 | 237 "linestyle", get (h, "linestyle"), |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
238 "linewidth", get (h, "linewidth"), |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
239 "marker", get (h, "marker"), |
17441 | 240 "markeredgecolor", get (h, "markeredgecolor"), |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
241 "markerfacecolor", get (h, "markerfacecolor"), |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
242 "markersize", get (h, "markersize")); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
243 endfunction |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
244 |
17441 | 245 function update_data (h, ~) |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
246 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
|
247 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
|
248 |
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
|
249 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
|
250 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
|
251 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
|
252 |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
253 nr = length (x); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
254 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
|
255 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
|
256 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
257 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
|
258 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
|
259 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
260 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
|
261 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
|
262 xs(ridx) = xtmp; |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
263 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
|
264 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
265 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
|
266 xs(ridx) = xtmp; |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
267 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
|
268 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
269 set (get (h, "children"), "xdata", xs, "ydata", ys); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
270 endfunction |
17073
55956e8e21c9
stairs.m: Overhaul to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
271 |
17441 | 272 |
273 %!demo | |
274 %! clf; | |
275 %! rand_1x10_data1 = [0.073, 0.455, 0.837, 0.124, 0.426, 0.781, 0.004, 0.024, 0.519, 0.698]; | |
276 %! y = rand_1x10_data1; | |
277 %! stairs (y); | |
278 %! title ('stairs() plot of y-data'); | |
279 | |
280 %!demo | |
281 %! clf; | |
282 %! x = 1:10; | |
283 %! rand_1x10_data2 = [0.014, 0.460, 0.622, 0.394, 0.531, 0.378, 0.466, 0.788, 0.342, 0.893]; | |
284 %! y = rand_1x10_data2; | |
285 %! [xs, ys] = stairs (x, y); | |
286 %! plot (xs, ys); | |
287 %! title ('plot() of stairs() generated data'); | |
288 | |
289 %!demo | |
290 %! clf; | |
291 %! stairs (1:9, '-o'); | |
292 %! title ('stairs() plot with linespec to modify marker'); | |
293 | |
294 %!demo | |
295 %! clf; | |
296 %! stairs (9:-1:1, 'marker', 's', 'markersize', 10, 'markerfacecolor', 'm'); | |
297 %! title ('stairs() plot with prop/val pairs to modify appearance'); | |
298 | |
299 %!demo | |
300 %! clf; | |
301 %! N = 11; | |
302 %! x = 0:(N-1); | |
303 %! y = rand (1, N); | |
304 %! hs = stairs (x(1), y(1)); | |
305 %! axis ([1, N-1 0, 1]); | |
306 %! title ('stairs plot data modified through handle'); | |
307 %! for k = 2:N | |
308 %! set (hs, 'xdata', x(1:k), 'ydata', y(1:k)); | |
309 %! drawnow (); | |
310 %! pause (0.2); | |
311 %! end | |
312 | |
313 ## Invisible figure used for tests | |
314 %!shared hf, hax | |
315 %! hf = figure ("visible", "off"); | |
316 %! hax = axes; | |
317 | |
318 %!error stairs () | |
319 %!error <Y must be a numeric 2-D vector> stairs (hax, {1}) | |
320 %!error <Y must be a numeric 2-D vector> stairs (ones (2,2,2)) | |
321 %!error <X and Y must be numeric 2-D vector> stairs ({1}, 1) | |
322 %!error <X and Y must be numeric 2-D vector> stairs (1, {1}) | |
323 %!error <X and Y must be numeric 2-D vector> stairs (ones (2,2,2), 1) | |
324 %!error <X and Y must be numeric 2-D vector> stairs (1, ones (2,2,2)) | |
325 %!error <X and Y sizes must match> stairs (1:2, 1:3) | |
326 | |
327 ## Close figure used for testing | |
328 %!test | |
329 %! close (hf); | |
330 |