Mercurial > hg > octave-lyh
annotate scripts/plot/stairs.m @ 17059:c935a0db31c6
errorbar.m: Update to use new __plt_get_axis_arg__.
* scripts/plot/errorbar.m: Update to use new __plt_get_axis_arg__.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 24 Jul 2013 23:12:46 -0700 |
parents | ddac88d32d6a |
children | 55956e8e21c9 |
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}) |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
23 ## @deftypefnx {Function File} {} stairs (@dots{}, @var{prop}, @var{val}) |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
24 ## @deftypefnx {Function File} {} stairs (@var{h}, @dots{}) |
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{}) |
6895 | 27 ## Produce a stairstep plot. The arguments may be vectors or matrices. |
3426 | 28 ## |
2311 | 29 ## If only one argument is given, it is taken as a vector of y-values |
3368 | 30 ## and the x coordinates are taken to be the indices of the elements. |
3426 | 31 ## |
16814
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
16752
diff
changeset
|
32 ## 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
|
33 ## 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
|
34 ## but not plotted. For example, |
3426 | 35 ## |
3368 | 36 ## @example |
37 ## stairs (x, y); | |
38 ## @end example | |
3426 | 39 ## |
3368 | 40 ## @noindent |
2311 | 41 ## and |
3426 | 42 ## |
3368 | 43 ## @example |
6895 | 44 ## @group |
3368 | 45 ## [xs, ys] = stairs (x, y); |
46 ## plot (xs, ys); | |
6895 | 47 ## @end group |
3368 | 48 ## @end example |
3426 | 49 ## |
3368 | 50 ## @noindent |
2311 | 51 ## are equivalent. |
16814
64e7bb01fce2
doc: Improve documentation for 2-D plot functions
Rik <rik@octave.org>
parents:
16752
diff
changeset
|
52 ## @seealso{plot} |
3368 | 53 ## @end deftypefn |
4 | 54 |
2314 | 55 ## Author: jwe |
56 | |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
57 function [xs, ys] = stairs (varargin) |
4 | 58 |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
59 [ax, varargin, nargin] = __plt_get_axis_arg__ ("stairs", varargin{:}); |
4 | 60 |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
61 if (nargin < 1) |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
62 print_usage (); |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
63 else |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
64 if (nargout > 1) |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
65 [h, xs, ys] = __stairs__ (false, varargin{:}); |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
66 else |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
67 oldax = gca (); |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
68 unwind_protect |
10549 | 69 axes (ax); |
70 newplot (); | |
71 [h, xxs, yys] = __stairs__ (true, varargin{:}); | |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
72 unwind_protect_cleanup |
10549 | 73 axes (oldax); |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
74 end_unwind_protect |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
75 endif |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
76 if (nargout == 1) |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
77 xs = h; |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
78 endif |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
79 endif |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
80 endfunction |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
81 |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
82 function [h, xs, ys] = __stairs__ (doplot, varargin) |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
83 |
9809
965487e00282
stairs.m (__stairs__): correct nargin check; new demos
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
84 if (nargin == 2 || ischar (varargin{2})) |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
85 y = varargin {1}; |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
8056
diff
changeset
|
86 varargin(1) = []; |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
87 if (ismatrix (y)) |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
88 if (isvector (y)) |
10549 | 89 y = y(:); |
6257 | 90 endif |
91 x = 1:rows (y); | |
4 | 92 endif |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
93 else |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
94 x = varargin{1}; |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
95 y = varargin{2}; |
8070
3b53b25e2550
Add data sources and line series
David Bateman <dbateman@free.fr>
parents:
8056
diff
changeset
|
96 varargin(1:2) = []; |
6257 | 97 endif |
98 | |
99 if (ndims (x) > 2 || ndims (y) > 2) | |
100 error ("stairs: expecting 2-d arguments"); | |
101 endif | |
102 | |
103 vec_x = isvector (x); | |
104 | |
105 if (vec_x) | |
106 x = x(:); | |
107 endif | |
108 | |
109 if (isvector (y)) | |
110 y = y(:); | |
111 endif | |
112 | |
113 if (ismatrix (y)) | |
114 [nr, nc] = size (y); | |
115 if (vec_x) | |
116 x = repmat (x, [1, nc]); | |
117 else | |
118 [x_nr, x_nc] = size (x); | |
119 if (x_nr != nr || x_nc != nc) | |
10549 | 120 error ("stairs: argument size mismatch"); |
4 | 121 endif |
122 endif | |
123 endif | |
124 | |
6257 | 125 len = 2*nr - 1; |
126 | |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
127 xs = ys = zeros (len, nc); |
6257 | 128 |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
129 xs(1,:) = x(1,:); |
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
130 ys(1,:) = y(1,:); |
6257 | 131 |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
132 xtmp = x(2:nr,:); |
6257 | 133 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
|
134 xs(ridx,:) = xtmp; |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
135 ys(ridx,:) = y(1:nr-1,:); |
6257 | 136 |
137 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
|
138 xs(ridx,:) = xtmp; |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
139 ys(ridx,:) = y(2:nr,:); |
6257 | 140 |
8243
ec4d9d657b17
Treat line style argument in stairs
David Bateman <dbateman@free.fr>
parents:
8079
diff
changeset
|
141 have_line_spec = false; |
8244 | 142 for i = 1 : length (varargin) |
8243
ec4d9d657b17
Treat line style argument in stairs
David Bateman <dbateman@free.fr>
parents:
8079
diff
changeset
|
143 arg = varargin {i}; |
ec4d9d657b17
Treat line style argument in stairs
David Bateman <dbateman@free.fr>
parents:
8079
diff
changeset
|
144 if ((ischar (arg) || iscell (arg)) && ! have_line_spec) |
ec4d9d657b17
Treat line style argument in stairs
David Bateman <dbateman@free.fr>
parents:
8079
diff
changeset
|
145 [linespec, valid] = __pltopt__ ("stairs", arg, false); |
ec4d9d657b17
Treat line style argument in stairs
David Bateman <dbateman@free.fr>
parents:
8079
diff
changeset
|
146 if (valid) |
10549 | 147 have_line_spec = true; |
148 varargin(i) = []; | |
149 break; | |
8243
ec4d9d657b17
Treat line style argument in stairs
David Bateman <dbateman@free.fr>
parents:
8079
diff
changeset
|
150 endif |
ec4d9d657b17
Treat line style argument in stairs
David Bateman <dbateman@free.fr>
parents:
8079
diff
changeset
|
151 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
152 endfor |
8243
ec4d9d657b17
Treat line style argument in stairs
David Bateman <dbateman@free.fr>
parents:
8079
diff
changeset
|
153 |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
154 if (doplot) |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
155 h = []; |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
156 unwind_protect |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
157 hold_state = get (gca (), "nextplot"); |
14872
c2dbdeaa25df
maint: use rows() and columns() to clarify m-files.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
158 for i = 1 : columns (y) |
10549 | 159 hg = hggroup (); |
160 h = [h; hg]; | |
161 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
|
162 |
10549 | 163 addproperty ("xdata", hg, "data", x(:,i).'); |
164 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
|
165 |
10549 | 166 addlistener (hg, "xdata", @update_data); |
167 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
|
168 |
10549 | 169 if (have_line_spec) |
170 tmp = line (xs(:,i).', ys(:,i).', "color", linespec.color, | |
171 "parent", hg); | |
172 else | |
173 tmp = line (xs(:,i).', ys(:,i).', "color", __next_line_color__ (), | |
174 "parent", hg); | |
175 endif | |
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
|
176 |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
177 addproperty ("color", hg, "linecolor", get (tmp, "color")); |
10549 | 178 addproperty ("linewidth", hg, "linelinewidth", get (tmp, "linewidth")); |
179 addproperty ("linestyle", hg, "linelinestyle", get (tmp, "linestyle")); | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
180 |
10549 | 181 addproperty ("marker", hg, "linemarker", get (tmp, "marker")); |
182 addproperty ("markerfacecolor", hg, "linemarkerfacecolor", | |
183 get (tmp, "markerfacecolor")); | |
184 addproperty ("markeredgecolor", hg, "linemarkeredgecolor", | |
185 get (tmp, "markeredgecolor")); | |
186 addproperty ("markersize", hg, "linemarkersize", | |
187 get (tmp, "markersize")); | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
188 |
10549 | 189 addlistener (hg, "color", @update_props); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
190 addlistener (hg, "linewidth", @update_props); |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
191 addlistener (hg, "linestyle", @update_props); |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
192 addlistener (hg, "marker", @update_props); |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
193 addlistener (hg, "markerfacecolor", @update_props); |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
194 addlistener (hg, "markeredgecolor", @update_props); |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
195 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
|
196 |
10549 | 197 if (! isempty (args)) |
198 set (hg, args{:}); | |
199 endif | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
200 endfor |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
201 unwind_protect_cleanup |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
202 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
|
203 end_unwind_protect |
736 | 204 else |
7746
95dce69538ec
Allow additional options to stairs plots
David Bateman <dbateman@free.fr>
parents:
7245
diff
changeset
|
205 h = 0; |
4 | 206 endif |
207 | |
208 endfunction | |
7245 | 209 |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
10736
diff
changeset
|
210 |
7245 | 211 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
212 %! clf; |
7245 | 213 %! x = 1:10; |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
10736
diff
changeset
|
214 %! rand_1x10_data1 = [0.073, 0.455, 0.837, 0.124, 0.426, 0.781, 0.004, 0.024, 0.519, 0.698]; |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
10736
diff
changeset
|
215 %! y = rand_1x10_data1; |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
216 %! stairs (x, y); |
7245 | 217 |
218 %!demo | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
219 %! clf; |
7245 | 220 %! x = 1:10; |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
10736
diff
changeset
|
221 %! rand_1x10_data2 = [0.014, 0.460, 0.622, 0.394, 0.531, 0.378, 0.466, 0.788, 0.342, 0.893]; |
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
10736
diff
changeset
|
222 %! y = rand_1x10_data2; |
7245 | 223 %! [xs, ys] = stairs (x, y); |
224 %! plot (xs, ys); | |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
225 |
9809
965487e00282
stairs.m (__stairs__): correct nargin check; new demos
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
226 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
227 %! clf; |
9809
965487e00282
stairs.m (__stairs__): correct nargin check; new demos
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
228 %! stairs (1:9); |
965487e00282
stairs.m (__stairs__): correct nargin check; new demos
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
229 |
965487e00282
stairs.m (__stairs__): correct nargin check; new demos
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
230 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
231 %! clf; |
9809
965487e00282
stairs.m (__stairs__): correct nargin check; new demos
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
232 %! [xs, ys] = stairs (9:-1:1); |
965487e00282
stairs.m (__stairs__): correct nargin check; new demos
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
233 %! plot (xs, ys); |
965487e00282
stairs.m (__stairs__): correct nargin check; new demos
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
234 |
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
|
235 %!demo |
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
|
236 %! clf; |
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
|
237 %! N = 11; |
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
|
238 %! x = 0:(N-1); |
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
|
239 %! y = rand (1, N); |
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
|
240 %! hs = stairs (x(1), y(1)); |
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
|
241 %! set (gca (), 'xlim', [1, N-1], 'ylim', [0, 1]); |
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
|
242 %! for k=2:N |
16828
ddac88d32d6a
Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
243 %! set (hs, 'xdata', x(1:k), 'ydata', y(1:k)); |
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
|
244 %! drawnow (); |
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
|
245 %! pause (0.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
|
246 %! end |
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
|
247 |
11363
a0dfd7e8e3e2
Assign data used in demo plots for reproducibility between runs
Rik <octave@nomad.inbox5.com>
parents:
10736
diff
changeset
|
248 |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
249 function update_props (h, d) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
250 set (get (h, "children"), "color", get (h, "color"), |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
251 "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
|
252 "linestyle", get (h, "linestyle"), |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
253 "marker", get (h, "marker"), |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
254 "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
|
255 "markeredgecolor", get (h, "markeredgecolor"), |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
256 "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
|
257 endfunction |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
258 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
259 function update_data (h, d) |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
260 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
|
261 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
|
262 |
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
|
263 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
|
264 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
|
265 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
|
266 |
8056
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
267 nr = length (x); |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
268 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
|
269 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
|
270 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
271 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
|
272 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
|
273 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
274 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
|
275 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
|
276 xs(ridx) = xtmp; |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
277 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
|
278 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
279 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
|
280 xs(ridx) = xtmp; |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
281 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
|
282 |
9a6f4713f765
Add area, bar, quiver and stair series graphics objects. Document them
David Bateman <dbateman@free.fr>
parents:
7746
diff
changeset
|
283 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
|
284 endfunction |