Mercurial > hg > octave-nkf
annotate scripts/plot/draw/area.m @ 18403:d7c88126ac03
fill.m: Don't replicate cdata matrix to x,y size when it is a string.
* fill.m: Don't replicate cdata matrix to x,y size when it is a string.
Add new demo using replication of cdata.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 22 Jan 2014 18:03:44 -0800 |
parents | d63878346099 |
children | a142f35f3cb6 446c46af4b42 |
rev | line source |
---|---|
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17572
diff
changeset
|
1 ## Copyright (C) 2007-2013 Michael Goffioul |
11523 | 2 ## Copyright (C) 2007-2009 David Bateman |
7146 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
8 ## the Free Software Foundation; either version 3 of the License, or (at | |
9 ## your option) any later version. | |
10 ## | |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
17 ## along with Octave; see the file COPYING. If not, see | |
18 ## <http://www.gnu.org/licenses/>. | |
19 | |
20 ## -*- texinfo -*- | |
15566
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
21 ## @deftypefn {Function File} {} area (@var{y}) |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
22 ## @deftypefnx {Function File} {} area (@var{x}, @var{y}) |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
23 ## @deftypefnx {Function File} {} area (@dots{}, @var{lvl}) |
7146 | 24 ## @deftypefnx {Function File} {} area (@dots{}, @var{prop}, @var{val}, @dots{}) |
17061
cae21eadc27b
area.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
17033
diff
changeset
|
25 ## @deftypefnx {Function File} {} area (@var{hax}, @dots{}) |
7146 | 26 ## @deftypefnx {Function File} {@var{h} =} area (@dots{}) |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17061
diff
changeset
|
27 ## Area plot of the columns of @var{y}. |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17061
diff
changeset
|
28 ## |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17061
diff
changeset
|
29 ## This plot shows the contributions of each column value to the row sum. It |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17061
diff
changeset
|
30 ## is functionally similar to @code{plot (@var{x}, cumsum (@var{y}, 2))}, |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17061
diff
changeset
|
31 ## except that the area under the curve is shaded. |
7146 | 32 ## |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17061
diff
changeset
|
33 ## If the @var{x} argument is omitted it defaults to @code{1:rows (@var{y})}. |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17061
diff
changeset
|
34 ## A value @var{lvl} can be defined that determines where the base level of |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17061
diff
changeset
|
35 ## the shading under the curve should be defined. The default level is 0. |
7146 | 36 ## |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17061
diff
changeset
|
37 ## Additional property/value pairs are passed directly to the underlying patch |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17061
diff
changeset
|
38 ## object. |
14001
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
39 ## |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17061
diff
changeset
|
40 ## If the first argument @var{hax} is an axes handle, then plot into this axis, |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17061
diff
changeset
|
41 ## rather than the current axes returned by @code{gca}. |
17061
cae21eadc27b
area.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
17033
diff
changeset
|
42 ## |
14001
5f0bb45e615c
doc: Update documentation for functions returning a graphics handle h (Bug #34761)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
43 ## The optional return value @var{h} is a graphics handle to the hggroup |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17211
diff
changeset
|
44 ## object comprising the area patch objects. The @qcode{"BaseValue"} property |
15566
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
45 ## of the hggroup can be used to adjust the level where shading begins. |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
46 ## |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
47 ## Example: Verify identity sin^2 + cos^2 = 1 |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
48 ## |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
49 ## @example |
16816
12005245b645
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
15566
diff
changeset
|
50 ## @group |
15566
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
51 ## t = linspace (0, 2*pi, 100)'; |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
52 ## y = [sin(t).^2, cos(t).^2)]; |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
53 ## area (t, y); |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17211
diff
changeset
|
54 ## legend ("sin^2", "cos^2", "location", "NorthEastOutside"); |
16816
12005245b645
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
15566
diff
changeset
|
55 ## @end group |
15566
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
56 ## @end example |
7146 | 57 ## @seealso{plot, patch} |
58 ## @end deftypefn | |
59 | |
7147 | 60 function h = area (varargin) |
7146 | 61 |
17061
cae21eadc27b
area.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
17033
diff
changeset
|
62 [hax, varargin, nargin] = __plt_get_axis_arg__ ("area", varargin{:}); |
7215 | 63 |
15566
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
64 if (nargin == 0) |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
65 print_usage (); |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
66 endif |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
67 |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
68 x = y = []; |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
69 bv = 0; |
17437
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
70 |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
71 num_numeric = find (cellfun ("isclass", varargin, "char"), 1) - 1; |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
72 if (isempty (num_numeric)) |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
73 num_numeric = nargin; |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
74 endif |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
75 |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
76 switch (num_numeric) |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
77 case 1 |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
78 y = varargin{1}; |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
79 case 2 |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
80 if (isscalar (varargin{2})) |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
81 y = varargin{1}; |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
82 bv = varargin{2}; |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
83 else |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
84 x = varargin{1}; |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
85 y = varargin{2}; |
7146 | 86 endif |
17437
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
87 case 3 |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
88 x = varargin{1}; |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
89 y = varargin{2}; |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
90 bv = varargin{3}; |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
91 otherwise |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
92 print_usage (); |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
93 endswitch |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
94 |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
95 if (! isreal (x) || ! isreal (y)) |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
96 error ("area: X and Y must be real vectors or matrices"); |
7146 | 97 endif |
17437
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
98 if (! isreal (bv) || ! isscalar (bv)) |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
99 error ("area: LVL must be a real scalar"); |
15566
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
100 endif |
17437
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
101 |
15566
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
102 if (isvector (y)) |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
103 y = y(:); |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
104 endif |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
105 if (isempty (x)) |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
106 x = repmat ([1:rows(y)]', 1, columns (y)); |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
107 elseif (isvector (x)) |
17061
cae21eadc27b
area.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
17033
diff
changeset
|
108 x = repmat (x(:), 1, columns (y)); |
15566
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
109 endif |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
110 |
17211
87ba70043bfc
Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents:
17190
diff
changeset
|
111 oldfig = []; |
17301
68bcac3c043a
Correct inversion accidentally introduced in cset 87ba70043bfc.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
112 if (! isempty (hax)) |
17211
87ba70043bfc
Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents:
17190
diff
changeset
|
113 oldfig = get (0, "currentfigure"); |
87ba70043bfc
Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents:
17190
diff
changeset
|
114 endif |
15566
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
115 unwind_protect |
17061
cae21eadc27b
area.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
17033
diff
changeset
|
116 hax = newplot (hax); |
17437
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
117 htmp = __area__ (hax, x, y, bv, varargin{num_numeric+1:end}); |
15566
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
118 unwind_protect_cleanup |
17061
cae21eadc27b
area.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
17033
diff
changeset
|
119 if (! isempty (oldfig)) |
cae21eadc27b
area.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
17033
diff
changeset
|
120 set (0, "currentfigure", oldfig); |
cae21eadc27b
area.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
17033
diff
changeset
|
121 endif |
15566
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
122 end_unwind_protect |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
123 |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
124 if (nargout > 0) |
17061
cae21eadc27b
area.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents:
17033
diff
changeset
|
125 h = htmp; |
15566
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
126 endif |
7146 | 127 |
128 endfunction | |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
129 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
130 function retval = __area__ (ax, x, y, bv, varargin) |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
131 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
132 y0 = bv * ones (1, rows (y)); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
133 y0 = zeros (1, rows (y)); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
134 retval = []; |
14872
c2dbdeaa25df
maint: use rows() and columns() to clarify m-files.
Rik <octave@nomad.inbox5.com>
parents:
14868
diff
changeset
|
135 for i = 1: columns (y); |
17437
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
136 |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
137 lc = __next_line_color__ (); |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
138 |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
139 ## Must occur after __next_line_color__ in order to work correctly. |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
140 hg = hggroup (); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
141 retval = [retval; hg]; |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
142 args = __add_datasource__ ("area", hg, {"x", "y"}, varargin{:}); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
143 |
17437
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
144 x1 = x(:, 1)'; |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
145 y1 = y(:, i)'; |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
146 addproperty ("xdata", hg, "data", x1); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
147 addproperty ("ydata", hg, "data", y1); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
148 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
149 addlistener (hg, "xdata", @update_data); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
150 addlistener (hg, "ydata", @update_data); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
151 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
152 if (i == 1) |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
153 h = patch (ax, [x1(1), x1, fliplr(x1)], [bv, y1, bv*ones(1, length(y1))], |
17437
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
154 lc, "parent", hg); |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
155 else |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
156 y1 = y0 + y1; |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
157 h = patch (ax, [x1(1), x1, fliplr(x1)], [y0(1), y1, fliplr(y0)], |
17437
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
158 lc, "parent", hg); |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
159 endif |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
160 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
161 y0 = y1; |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
162 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
163 addproperty ("basevalue", hg, "data", bv); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
164 addlistener (hg, "basevalue", @move_baseline); |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
165 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
166 addproperty ("edgecolor", hg, "patchedgecolor", get (h, "edgecolor")); |
17437
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
167 addproperty ("facecolor", hg, "patchfacecolor", get (h, "facecolor")); |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
168 addproperty ("linestyle", hg, "patchlinestyle", get (h, "linestyle")); |
17437
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
169 addproperty ("linewidth", hg, "patchlinewidth", get (h, "linewidth")); |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
170 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
171 addlistener (hg, "edgecolor", @update_props); |
17437
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
172 addlistener (hg, "facecolor", @update_props); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
173 addlistener (hg, "linestyle", @update_props); |
17437
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
174 addlistener (hg, "linewidth", @update_props); |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
175 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
176 addproperty ("areagroup", hg, "data"); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
177 set (retval, "areagroup", retval); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
178 |
17527
76614e624818
Add "HitTestArea" property to certain hggroups for Matlab compatibility
Rik <rik@octave.org>
parents:
17437
diff
changeset
|
179 ## Matlab property, although Octave does not implement it. |
76614e624818
Add "HitTestArea" property to certain hggroups for Matlab compatibility
Rik <rik@octave.org>
parents:
17437
diff
changeset
|
180 addproperty ("hittestarea", hg, "radio", "on|{off}", "off"); |
76614e624818
Add "HitTestArea" property to certain hggroups for Matlab compatibility
Rik <rik@octave.org>
parents:
17437
diff
changeset
|
181 |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
182 if (! isempty (args)) |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
183 set (hg, args{:}); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
184 endif |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
185 endfor |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
186 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
187 endfunction |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
188 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
189 function update_props (h, d) |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
190 kids = get (h, "children"); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
191 set (kids, "edgecolor", get (h, "edgecolor"), |
17437
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
192 "facecolor", get (h, "facecolor"), |
15566
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
193 "linestyle", get (h, "linestyle"), |
17437
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
194 "linewidth", get (h, "linewidth")); |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
195 endfunction |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
196 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
197 function move_baseline (h, d) |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
198 persistent recursion = false; |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
199 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
200 ## Don't allow recursion |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
201 if (! recursion) |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
202 unwind_protect |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
203 recursion = true; |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
204 hlist = get (h, "areagroup"); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
205 b0 = get (h, "basevalue"); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
206 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
207 for hh = hlist(:)' |
10549 | 208 if (hh != h) |
209 b1 = get (hh, "basevalue"); | |
210 if (b1 != b0) | |
211 set (hh, "basevalue", b0); | |
212 endif | |
213 endif | |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
214 endfor |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
215 update_data (h, d); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
216 unwind_protect_cleanup |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
217 recursion = false; |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
218 end_unwind_protect |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
219 endif |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
220 endfunction |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
221 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
222 function update_data (h, d) |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
223 hlist = get (h, "areagroup"); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
224 bv = get (h, "basevalue"); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
225 for i = 1 : length (hlist) |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
226 hh = hlist(i); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
227 x1 = get (hh, "xdata")(:); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
228 y1 = get (hh, "ydata")(:); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
229 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
230 set (get (hh, "children"), "xdata", [x1(1); x1; flipud(x1)]); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
231 if (i == 1) |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
232 set (get (hh, "children"), "ydata", [bv; y1; bv*ones(length(y1), 1)]); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
233 else |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
234 y1 = y0 + y1; |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
235 set (get (hh, "children"), "ydata", [y0(1); y1; flipud(y0)]); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
236 endif |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
237 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
238 y0 = y1; |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
239 endfor |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
240 endfunction |
15566
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
241 |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
242 |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
243 %!demo |
17336
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
17301
diff
changeset
|
244 %! ## Verify identity sin^2 + cos^2 = 1 |
15566
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
245 %! clf; |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
246 %! t = linspace (0, 2*pi, 100)'; |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
247 %! y = [sin(t).^2, cos(t).^2]; |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
248 %! area (t, y); |
16917
4bbc4b703fe4
area.m: tight axis limits for demo.
Ben Abbott <bpabbott@mac.com>
parents:
16816
diff
changeset
|
249 %! axis tight |
15566
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
250 %! legend ('sin^2', 'cos^2', 'location', 'NorthEastOutside'); |
17190
df4c4b7708a4
Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
251 %! title ('area() plot'); |
15566
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
252 |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
253 %!demo |
17336
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
17301
diff
changeset
|
254 %! ## Show effects of setting BaseValue |
15566
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
255 %! clf; |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
256 %! x = [-2:0.1:2]'; |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
257 %! y = x.^2 - 1; |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
258 %! subplot (1, 2, 1) |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
259 %! area (x, y); |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
260 %! title ({'Parabola y = x^2 -1';'BaseValue = 0'}); |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
261 %! subplot (1, 2, 2) |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
262 %! h = area (x, y); |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
263 %! set (h, 'basevalue', -1); |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
264 %! title ({'Parabola y = x^2 -1';'BaseValue = -1'}); |
ab1c6e6d1be6
area.m: Add demos and redo docstring.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
265 |
17033
02679492b0c6
Add demo to area.m to demonstrate "ydata" updater.
Ben Abbott <bpabbott@mac.com>
parents:
16917
diff
changeset
|
266 %!demo |
17190
df4c4b7708a4
Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
267 %! clf; |
17033
02679492b0c6
Add demo to area.m to demonstrate "ydata" updater.
Ben Abbott <bpabbott@mac.com>
parents:
16917
diff
changeset
|
268 %! x = 0:10; |
02679492b0c6
Add demo to area.m to demonstrate "ydata" updater.
Ben Abbott <bpabbott@mac.com>
parents:
16917
diff
changeset
|
269 %! y = rand (size (x)); |
02679492b0c6
Add demo to area.m to demonstrate "ydata" updater.
Ben Abbott <bpabbott@mac.com>
parents:
16917
diff
changeset
|
270 %! h = area (x, y); |
02679492b0c6
Add demo to area.m to demonstrate "ydata" updater.
Ben Abbott <bpabbott@mac.com>
parents:
16917
diff
changeset
|
271 %! set (h, 'ydata', sort (get (h, 'ydata'))) |
17190
df4c4b7708a4
Add titles and clean-up plotting %!demos.
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
272 %! title ('area() plot of sorted data'); |
17336
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
17301
diff
changeset
|
273 |
17437
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
274 %% Test input validation |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
275 %!error area () |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
276 %!error area (1,2,3,4) |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
277 %!error <X and Y must be real vectors or matrices> area ({1}) |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
278 %!error <X and Y must be real vectors or matrices> area (1+i) |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
279 %!error <X and Y must be real vectors or matrices> area (1:2, {1, 2}) |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
280 %!error <X and Y must be real vectors or matrices> area (1:2, [1 1+i]) |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
281 %!error <LVL must be a real scalar> area (1, i) |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
282 %!error <LVL must be a real scalar> area (1, 2, ones (2,2)) |
cf5a8fccfc63
area.m: Overhaul function to fix color cycling.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
283 |