annotate scripts/plot/draw/private/__ezplot__.m @ 31123:18b8f73595e0

Suppress warning for inline() when used intentionally in core Octave (bug #62682). * fplot.m, __ezplot__.m: Temporarily suppress warning for "Octave:legacy-function" so that intentional use of inline() does not produce a confusing warning.
author Rik <rik@octave.org>
date Tue, 05 Jul 2022 10:38:41 -0700
parents e1788b1a315f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27928
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
2 ##
30569
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30384
diff changeset
3 ## Copyright (C) 2007-2022 The Octave Project Developers
27923
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26671
diff changeset
4 ##
27928
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
7 ##
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
8 ## This file is part of Octave.
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22351
diff changeset
13 ## (at your option) any later version.
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
14 ##
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22351
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22351
diff changeset
18 ## GNU General Public License for more details.
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
19 ##
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27928
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27924
diff changeset
24 ########################################################################
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
25
8812
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8046
diff changeset
26 ## -*- texinfo -*-
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
27 ## @deftypefn {} {[@var{h}, @var{needusage}] =} __ezplot__ (@var{pltfcn}, @var{varargin})
8812
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8046
diff changeset
28 ## Undocumented internal function.
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8046
diff changeset
29 ## @end deftypefn
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
30
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
31 ## Overview: This function is the back-end for the 9 ez* plot functions.
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
32 ## As such, most of the function is actually dedicated to sorting
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
33 ## out the inputs and verifying that the particular ez* function
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
34 ## called was called correctly. The actual plotting occurs near
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
35 ## the end in an unwind_protect block.
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
36
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
37 function [h, needusage] = __ezplot__ (pltfcn, varargin)
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
38
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
39 ezfcn = ["ez" pltfcn];
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
40
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
41 [hax, varargin, nargin] = __plt_get_axis_arg__ (ezfcn, varargin{:});
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
42
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
43 ## Define outputs early in case of shorting out of function with return;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
44 h = [];
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
45 needusage = false;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
46 if (nargin < 1)
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
47 needusage = true;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
48 return;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
49 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
50
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
51 iscontour = strncmp (pltfcn, "contour", 7);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
52
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
53 ## Defaults for ezplot
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
54 isplot = true;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
55 isplot3 = false;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
56 ispolar = false;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
57 nargs = 1;
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
58 switch (pltfcn)
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
59 case "plot"
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
60 ## defaults already set
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
61
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
62 case "plot3"
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
63 isplot = false;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
64 isplot3 = true;
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
65
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
66 case "polar"
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
67 isplot = false;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
68 ispolar = true;
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
69
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
70 otherwise
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
71 ## contour, mesh, surf plots
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
72 isplot = false;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
73 nargs = 2;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
74
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
75 endswitch
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
76
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
77 parametric = false;
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
78 fcn = varargin{1};
31123
18b8f73595e0 Suppress warning for inline() when used intentionally in core Octave (bug #62682).
Rik <rik@octave.org>
parents: 30898
diff changeset
79 ## Don't warn about intentional use of inline functions (Bug #62682)
18b8f73595e0 Suppress warning for inline() when used intentionally in core Octave (bug #62682).
Rik <rik@octave.org>
parents: 30898
diff changeset
80 warning ("off", "Octave:legacy-function", "local");
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
81 if (ischar (fcn))
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
82 if (exist (fcn, "file") || exist (fcn, "builtin"))
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
83 fcn = str2func (fcn); # convert to function handle
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
84 else
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
85 fcn = vectorize (inline (fcn)); # convert to inline function
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
86 endif
20499
c0566df8cde3 Generate correct ezplot for 2-input functions (bug #46004).
Rik <rik@octave.org>
parents: 19697
diff changeset
87 endif
c0566df8cde3 Generate correct ezplot for 2-input functions (bug #46004).
Rik <rik@octave.org>
parents: 19697
diff changeset
88
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
89 if (isa (fcn, "inline"))
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
90 argids = argnames (fcn);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
91 if (isplot && length (argids) == 2)
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
92 nargs = 2;
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
93 elseif (numel (argids) != nargs)
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
94 error ("%s: expecting a function of %d arguments", ezfcn, nargs);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
95 endif
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
96 fcn = vectorize (fcn);
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
97 fstr = formula (fcn);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
98 if (isplot)
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
99 xarg = argids{1};
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
100 if (nargs == 2)
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
101 yarg = argids{2};
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
102 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
103 yarg = "";
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
104 endif
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
105 elseif (isplot3)
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
106 xarg = "x";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
107 yarg = "y";
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
108 elseif (isplot || ispolar)
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
109 xarg = "";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
110 yarg = "";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
111 else
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
112 xarg = argids{1};
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
113 yarg = argids{2};
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
114 endif
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
115 elseif (is_function_handle (fcn))
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
116 fstr = func2str (fcn);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
117 idx = index (fstr, ')');
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
118 if (idx != 0)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
119 args = regexp (fstr(3:(idx-1)), '\w+', 'match');
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
120 fstr = fstr(idx+2:end); # remove '@(x) ' from string name
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
121 else
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
122 args = {"x"};
20499
c0566df8cde3 Generate correct ezplot for 2-input functions (bug #46004).
Rik <rik@octave.org>
parents: 19697
diff changeset
123 try
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
124 if (builtin ("nargin", fcn) == 2)
20499
c0566df8cde3 Generate correct ezplot for 2-input functions (bug #46004).
Rik <rik@octave.org>
parents: 19697
diff changeset
125 args{2} = "y";
c0566df8cde3 Generate correct ezplot for 2-input functions (bug #46004).
Rik <rik@octave.org>
parents: 19697
diff changeset
126 endif
c0566df8cde3 Generate correct ezplot for 2-input functions (bug #46004).
Rik <rik@octave.org>
parents: 19697
diff changeset
127 end_try_catch
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
128 endif
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
129 if (isplot && length (args) == 2)
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
130 nargs = 2;
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
131 elseif (numel (args) != nargs)
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
132 error ("%s: expecting a function of %d arguments", ezfcn, nargs);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
133 endif
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
134 if (isplot)
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
135 xarg = args{1};
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
136 if (nargs == 2)
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
137 yarg = args{2};
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
138 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
139 yarg = "";
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
140 endif
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
141 elseif (isplot3)
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
142 xarg = "x";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
143 yarg = "y";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
144 elseif (ispolar)
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
145 xarg = "";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
146 yarg = "";
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
147 else
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
148 xarg = args{1};
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
149 yarg = args{2};
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
150 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
151 else
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
152 error ("%s: F must be a string or function handle", ezfcn);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
153 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
154
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
155 if (nargin > 2 || (nargin == 2 && isplot))
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
156 funx = fcn;
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
157 fstrx = fstr;
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
158 funy = varargin{2};
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
159 if (ischar (funy) && ! strcmp (funy, "circ") && ! strcmp (funy, "animate"))
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
160 parametric = true;
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
161 if (exist (funy, "file") || exist (funy, "builtin"))
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
162 funy = inline ([funy "(t)"]);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
163 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
164 funy = vectorize (inline (funy));
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
165 endif
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
166 if (numel (argnames (funy)) != nargs)
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
167 error ("%s: expecting a function of %d arguments", ezfcn, nargs);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
168 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
169 fstry = formula (funy);
28432
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27928
diff changeset
170 elseif (isa (funy, "inline"))
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
171 parametric = true;
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
172 if (numel (argnames (funy)) != nargs)
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
173 error ("%s: expecting a function of %d arguments", ezfcn, nargs);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
174 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
175 funy = vectorize (funy);
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
176 fstry = formula (funy);
25806
23483673ba43 Use is_function_handle instead of isa (x, "function_handle").
Rik <rik@octave.org>
parents: 25054
diff changeset
177 elseif (is_function_handle (funy))
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
178 parametric = true;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
179 fstry = func2str (funy);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
180 idx = index (fstry, ')');
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
181 if (idx != 0)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
182 args = regexp (fstry(3:(idx-1)), '\w+', 'match');
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
183 fstry = fstry(idx+2:end); # remove '@(x) ' from string name
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
184 else
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
185 args = {"y"};
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
186 endif
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
187 if (numel (args) != nargs)
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
188 error ("%s: expecting a function of %d arguments", ezfcn, nargs);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
189 endif
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
190 endif
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
191
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
192 if (! parametric && isplot3)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
193 needusage = true; # Can't call non-parametric ezplot3
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
194 return;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
195 elseif (parametric && isplot)
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
196 if (nargs == 2)
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
197 error ("%s: can not define a parametric function in this manner", ezfcn);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
198 else
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
199 xarg = "x";
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
200 yarg = "y";
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
201 endif
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
202 elseif (parametric)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
203 funz = varargin{3};
11149
fe3c3dfc07eb style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents: 11032
diff changeset
204 if (ischar (funz) && ! strcmp (funz, "circ")
fe3c3dfc07eb style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents: 11032
diff changeset
205 && ! strcmp (funz, "animate"))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
206 if (exist (funz, "file") || exist (funz, "builtin"))
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
207 funz = inline ([funz "(t)"]);
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
208 else
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
209 funz = vectorize (inline (funz));
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
210 endif
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
211 if (numel (argnames (funz)) > nargs)
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
212 error ("%s: expecting a function of %d arguments", ezfcn, nargs);
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
213 endif
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
214 fstrz = formula (funz);
28432
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 27928
diff changeset
215 elseif (isa (funz, "inline"))
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
216 if (numel (argnames (funz)) != nargs)
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
217 error ("%s: expecting a function of %d arguments", ezfcn, nargs);
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
218 endif
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
219 funz = vectorize (funz);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
220 fstrz = formula (funz);
25806
23483673ba43 Use is_function_handle instead of isa (x, "function_handle").
Rik <rik@octave.org>
parents: 25054
diff changeset
221 elseif (is_function_handle (funz))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
222 fstrz = func2str (funz);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
223 idx = index (fstrz, ')');
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
224 if (idx != 0)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
225 args = regexp (fstrz(3:(idx-1)), '\w+', 'match');
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
226 fstrz = fstrz(idx+2:end); # remove '@(x) ' from string name
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
227 else
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
228 args = {"z"};
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
229 endif
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
230 if (numel (args) != nargs)
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
231 error ("%s: expecting a function of %d arguments", ezfcn, nargs);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
232 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
233 else
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
234 error ("%s: parametric plots require 3 functions", ezfcn);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
235 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
236 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
237 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
238
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
239 if ((isplot && nargs != 2) || isplot3 || ispolar)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
240 n = 500; # default for point-style functions like plot
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
241 else
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
242 n = 60; # default for meshgrid style functions like contour, surf
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
243 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
244 domain = [];
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
245 circ = false;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
246 animate = false;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
247 if (parametric)
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
248 if (isplot)
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
249 iarg = 3;
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
250 else
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
251 iarg = 4;
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
252 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
253 else
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
254 iarg = 2;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
255 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
256 while (iarg <= nargin)
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
257 arg = varargin{iarg++};
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
258 if (ischar (arg) && strcmp (arg, "circ"))
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
259 circ = true;
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
260 elseif (ischar (arg) && strcmp (arg, "animate"))
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
261 animate = true;
21560
96c768d898f0 Use stricter input validation for ezplot N, DOM inputs (bug #46952).
Rik <rik@octave.org>
parents: 21385
diff changeset
262 elseif (isscalar (arg) && (n == 60 || n == 500))
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
263 n = arg;
21560
96c768d898f0 Use stricter input validation for ezplot N, DOM inputs (bug #46952).
Rik <rik@octave.org>
parents: 21385
diff changeset
264 elseif (numel (arg) == 2 && isempty (domain))
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
265 domain = [arg(1) arg(2) arg(1) arg(2)];
21560
96c768d898f0 Use stricter input validation for ezplot N, DOM inputs (bug #46952).
Rik <rik@octave.org>
parents: 21385
diff changeset
266 elseif (numel (arg) == 4 && isempty (domain))
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
267 domain = arg(:).';
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
268 else
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
269 error ("%s: expecting scalar N, or 2-/4-element vector DOM", ezfcn);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
270 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
271 endwhile
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
272
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
273 if (circ && (iscontour || isplot3 || isplot))
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
274 needusage = true;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
275 return;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
276 elseif (circ && parametric)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
277 error ("%s: can not have both circular domain and parametric function",
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
278 ezfcn);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
279 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
280
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
281 if (animate && ! isplot3)
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
282 error ("%s: animate option only valid for ezplot3", ezfcn);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
283 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
284
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
285 if (parametric)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
286 ## Make the label strings pretty by removing extra spaces between base
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
287 ## and exponent, the '.' in vectorized code, and the '*' for multiply.
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
288 fstrx = regexprep (regexprep (regexprep (fstrx,
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
289 '\s*\.?(?:\^|\*\*)\s*','^'), '\.([/+-])', '$1'), '\s*\.?\*\s*', ' ');
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
290 fstry = regexprep (regexprep (regexprep (fstry,
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
291 '\s*\.?(?:\^|\*\*)\s*','^'), '\.([/+-])', '$1'), '\s*\.?\*\s*', ' ');
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
292 if (isplot)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
293 fstr = ["x = " fstrx ", y = " fstry];
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
294 else
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
295 fstrz = regexprep (regexprep (regexprep (fstrz,
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
296 '\s*\.?(?:\^|\*\*)\s*','^'), '\.([/+-])', '$1'), '\s*\.?\*\s*', ' ');
22308
b756cea4fdea __ezplot__.m: Fix Matlab incompatibilities.
Rik <rik@octave.org>
parents: 21561
diff changeset
297 fstr = ["x = " fstrx ", y = " fstry ", z = " fstrz];
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
298 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
299 else
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
300 fstr = regexprep (regexprep (regexprep (fstr,
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
301 '\s*\.?(?:\^|\*\*)\s*','^'), '\.([/+-])', '$1'), '\s*\.?\*\s*', ' ');
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
302 if (isplot && nargs == 2)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
303 fstr = [fstr " = 0"]; # make title string of implicit function
22309
46d39db0c571 __ezplot__.m: Add 'r = ' to the title string for ezpolar plots.
Rik <rik@octave.org>
parents: 22308
diff changeset
304 elseif (ispolar)
46d39db0c571 __ezplot__.m: Add 'r = ' to the title string for ezpolar plots.
Rik <rik@octave.org>
parents: 22308
diff changeset
305 fstr = ["r = " fstr];
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
306 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
307 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
308
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
309 if (isempty (domain))
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
310 auto_domain = true;
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
311 if (isplot3 || ispolar)
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
312 domain = [0, 2*pi, 0, 2*pi];
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
313 else
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
314 domain = [-2*pi, 2*pi, -2*pi, 2*pi];
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
315 endif
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
316 else
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
317 auto_domain = false;
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
318 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
319
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
320 auto_domain_done = false;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
321 do
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
322 domain_ok = true;
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
323
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
324 if ((isplot && nargs == 1) || isplot3 || ispolar)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
325 X = linspace (domain(1), domain(2), n);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
326 elseif (isplot && numel (domain) == 2)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
327 x = linspace (domain(1), domain(2), n);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
328 [X, Y] = meshgrid (x, x);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
329 elseif (circ)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
330 ## To plot on circular domain develop grid in polar coordinates
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
331 ## and then switch these to Cartesian coordinates.
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
332 cent = [domain(1) + domain(2), domain(3) + domain(4)] / 2;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
333 rmax = sqrt ((domain(2) - cent(1))^2 + (domain(4) - cent(2))^2);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
334 r = linspace (0, rmax, n);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
335 t = linspace (0, 2*pi, n);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
336 [T, R] = meshgrid (t, r);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
337 X = R .* cos (T) + cent(1);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
338 Y = R .* sin (T) + cent(2);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
339 domain = [-rmax+cent(1), +rmax+cent(1), -rmax+cent(2), +rmax+cent(2)];
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
340 else # contour, mesh, surf plots
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
341 x = linspace (domain(1), domain(2), n);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
342 y = linspace (domain(3), domain(4), n);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
343 [X, Y] = meshgrid (x, y);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
344 endif
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
345
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
346 if (parametric)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
347 if (isplot)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
348 XX = feval (funx, X);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
349 Z = feval (funy, X);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
350 X = XX;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
351 elseif (isplot3)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
352 Z = feval (funz, X);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
353 XX = feval (funx, X);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
354 YY = feval (funy, X);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
355 X = XX;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
356 Y = YY;
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
357 else
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
358 Z = feval (funz, X, Y);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
359 XX = feval (funx, X, Y);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
360 YY = feval (funy, X, Y);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
361 X = XX;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
362 Y = YY;
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
363
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
364 ## Eliminate the singularities
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
365 X = __eliminate_sing__ (X);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
366 Y = __eliminate_sing__ (Y);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
367 Z = __eliminate_sing__ (Z);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
368 endif
28948
e3a337a57588 maint: Use only one '#' character for comments that trail code.
Rik <rik@octave.org>
parents: 28432
diff changeset
369 else # non-parametric plots
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
370 if (isplot && nargs == 2)
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
371 Z = feval (fcn, X, Y);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
372
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
373 ## Matlab returns line objects for this case and so can't call
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
374 ## contour directly as it returns patch objects to allow colormaps
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
375 ## to work with contours. Therefore recreate the lines from the
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
376 ## output for contourc, and store in cell arrays.
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
377 [c, ~] = contourc (X, Y, Z, [0, 0]);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
378
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
379 i = 1;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
380 XX = YY = {};
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
381 while (i < length (c))
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
382 clev = c(1,i);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
383 clen = c(2,i);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
384 XX = [XX, {c(1, i+1:i+clen)}];
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
385 YY = [YY, {c(2, i+1:i+clen)}];
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
386 i += clen+1;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
387 endwhile
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
388 else
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
389 if (ispolar)
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
390 Z = feval (fcn, X);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
391 ## FIXME: Why aren't singularities eliminated for polar plots?
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
392 elseif (isplot)
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
393 Z = feval (fcn, X);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
394 ## Eliminate the singularities
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
395 Z = __eliminate_sing__ (Z);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
396 domain = find_valid_domain (X, [], Z);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
397 elseif (iscontour)
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
398 Z = feval (fcn, X, Y);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
399 Z = __eliminate_sing__ (Z);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
400 else # mesh, surf plots
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
401 Z = feval (fcn, X, Y);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
402 Z = __eliminate_sing__ (Z);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
403 if (circ)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
404 ## Use domain calculated at the start.
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
405 ## The X, Y grids are non-monotonic after conversion from polar
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
406 ## coordinates and find_valid_domain fails.
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
407
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
408 elseif (auto_domain && ! auto_domain_done)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
409 valid_domain = find_valid_domain (X, Y, Z);
22882
9b096bffc10d Fix plotting of constant functions with ezplot (bug #49766).
Rik <rik@octave.org>
parents: 22767
diff changeset
410 domain_ok = all (domain == valid_domain);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
411 domain = valid_domain;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
412 auto_domain_done = true; # ensures only 1 round of do loop done
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
413 else
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
414 if (! auto_domain_done)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
415 domain = find_valid_domain (X, Y, Z);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
416 endif
17306
09543e9c8f40 Use explicit form of end (endif, endfor, etc.) in core m-files.
Rik <rik@octave.org>
parents: 17301
diff changeset
417 endif
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
418 endif
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
419 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
420 endif
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
421 until (domain_ok)
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
422
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
423 ## Now, actually call the correct plot function with valid data and domain.
17211
87ba70043bfc Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents: 17167
diff changeset
424 oldfig = [];
17301
68bcac3c043a Correct inversion accidentally introduced in cset 87ba70043bfc.
Rik <rik@octave.org>
parents: 17211
diff changeset
425 if (! isempty (hax))
17211
87ba70043bfc Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents: 17167
diff changeset
426 oldfig = get (0, "currentfigure");
87ba70043bfc Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents: 17167
diff changeset
427 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
428 unwind_protect
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
429 hax = newplot (hax);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
430 if (iscontour)
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
431 [~, h] = feval (pltfcn, hax, X, Y, Z);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
432 elseif (isplot && nargs == 2)
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
433 h = zeros (length (XX), 1);
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
434 hold_state = get (hax, "nextplot");
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
435 for i = 1 : length (XX)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
436 if (i == 1)
22308
b756cea4fdea __ezplot__.m: Fix Matlab incompatibilities.
Rik <rik@octave.org>
parents: 21561
diff changeset
437 h(1) = plot (hax, XX{1}, YY{1});
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
438 set (hax, "nextplot", "add");
22308
b756cea4fdea __ezplot__.m: Fix Matlab incompatibilities.
Rik <rik@octave.org>
parents: 21561
diff changeset
439 color = get (h(1), "color");
b756cea4fdea __ezplot__.m: Fix Matlab incompatibilities.
Rik <rik@octave.org>
parents: 21561
diff changeset
440 else
b756cea4fdea __ezplot__.m: Fix Matlab incompatibilities.
Rik <rik@octave.org>
parents: 21561
diff changeset
441 h(i) = plot (hax, XX{i}, YY{i}, "color", color);
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9896
diff changeset
442 endif
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
443 endfor
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
444 set (hax, "nextplot", hold_state);
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
445 axis (hax, domain);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
446 elseif (isplot || ispolar)
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
447 h = feval (pltfcn, hax, X, Z);
18718
a50d0d85dc73 Set axis equal for 2D parametric plots done with ezplot.
Rik <rik@octave.org>
parents: 17744
diff changeset
448 if (isplot)
a50d0d85dc73 Set axis equal for 2D parametric plots done with ezplot.
Rik <rik@octave.org>
parents: 17744
diff changeset
449 if (! parametric)
a50d0d85dc73 Set axis equal for 2D parametric plots done with ezplot.
Rik <rik@octave.org>
parents: 17744
diff changeset
450 axis (hax, domain);
a50d0d85dc73 Set axis equal for 2D parametric plots done with ezplot.
Rik <rik@octave.org>
parents: 17744
diff changeset
451 else
a50d0d85dc73 Set axis equal for 2D parametric plots done with ezplot.
Rik <rik@octave.org>
parents: 17744
diff changeset
452 axis ("equal");
a50d0d85dc73 Set axis equal for 2D parametric plots done with ezplot.
Rik <rik@octave.org>
parents: 17744
diff changeset
453 endif
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
454 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
455 elseif (isplot3)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
456 if (animate)
26671
fec69a310833 __ezplot__.m: for ezplot3, draw "animate" plot just once.
Rik <rik@octave.org>
parents: 26379
diff changeset
457 comet3 (hax, X, Y, Z);
fec69a310833 __ezplot__.m: for ezplot3, draw "animate" plot just once.
Rik <rik@octave.org>
parents: 26379
diff changeset
458 else
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
459 h = feval (pltfcn, hax, X, Y, Z);
8046
c4482fc30c7f Add the ezplot function
David Bateman <dbateman@free.fr>
parents: 7540
diff changeset
460 endif
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
461 grid (hax, "on");
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
462 zlabel (hax, "z");
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
463 else # mesh and surf plots
30898
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30569
diff changeset
464 h = feval (pltfcn, hax, X, Y, Z);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
465 ## FIXME: surf, mesh should really do a better job of setting zlim
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
466 if (! parametric)
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
467 axis (hax, domain);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
468 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
469 endif
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
470 xlabel (hax, xarg);
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
471 ylabel (hax, yarg);
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
472 title (hax, fstr);
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
473 unwind_protect_cleanup
17054
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
474 if (! isempty (oldfig))
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
475 set (0, "currentfigure", oldfig);
27b3a675ea6b __ezplot__.m: Update to use new __plt_get_axis_arg__.
Rik <rik@octave.org>
parents: 16993
diff changeset
476 endif
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
477 end_unwind_protect
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
478
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
479 endfunction
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
480
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
481 ## Eliminate bad data (complex values, infinities, singularities)
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
482 function x = __eliminate_sing__ (x)
30384
363fb10055df maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29364
diff changeset
483
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
484 if (iscomplex (x))
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
485 x(imag (x) != 0) = NaN;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
486 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
487 x(isinf (x)) = NaN;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
488 ## High rates of curvature are treated as singularities
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
489 threshold = 0.2 * (max (x(:)) - min (x(:)));
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
490 x(abs (del2 (x)) > threshold) = NaN;
30384
363fb10055df maint: Style check m-files ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29364
diff changeset
491
7337
e70789e0cd92 [project @ 2007-12-28 21:04:44 by jwe]
jwe
parents:
diff changeset
492 endfunction
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
493
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
494 ## Find: 1) range of function where there are not NaN values,
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
495 ## 2) function is changing (not just flat surface)
22767
212333a97d8d maint: Remove dangling ';' from m-file function declarations.
Rik <rik@octave.org>
parents: 22755
diff changeset
496 function domain = find_valid_domain (X, Y, Z)
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
497
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
498 if (isvector (Z))
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
499 ## 2-D data for isplot
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
500 domain = [X(1) X(end)];
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
501
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
502 ## Guess a range which includes the "mass" of the data by using a
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
503 ## median-based approach. The center 3/4 of the data is used to
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
504 ## determine the range of the data.
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
505 ## This seems to be vaguely what Matlab does, but can't be sure.
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
506 XX = sort (Z(isfinite (Z)));
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
507 if (length (X) > 4)
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
508 irlo = XX(fix (1/8 * length (XX)));
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
509 irhi = XX(fix (7/8 * length (XX)));
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
510 d = irhi - irlo;
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
511 domain(3) = max (XX(1) - d/8, irlo - d);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
512 domain(4) = min (XX(end) + d/8, irhi + d);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
513 else
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
514 domain(3:4) = [XX(1), XX(end)];
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
515 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
516
22882
9b096bffc10d Fix plotting of constant functions with ezplot (bug #49766).
Rik <rik@octave.org>
parents: 22767
diff changeset
517 ## Handle exceptional case of constant function
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22882
diff changeset
518 if (domain(3) == domain(4))
22882
9b096bffc10d Fix plotting of constant functions with ezplot (bug #49766).
Rik <rik@octave.org>
parents: 22767
diff changeset
519 domain(3) -= 1;
9b096bffc10d Fix plotting of constant functions with ezplot (bug #49766).
Rik <rik@octave.org>
parents: 22767
diff changeset
520 domain(4) += 1;
9b096bffc10d Fix plotting of constant functions with ezplot (bug #49766).
Rik <rik@octave.org>
parents: 22767
diff changeset
521 endif
9b096bffc10d Fix plotting of constant functions with ezplot (bug #49766).
Rik <rik@octave.org>
parents: 22767
diff changeset
522
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
523 else
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
524 ## 3-D data such as mesh, surf
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
525 Zfinite = ! isnan (Z);
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
526 Zrows = any (Zfinite, 2);
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
527 rmin = find (Zrows, 1, "first");
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
528 rmax = find (Zrows, 1, "last");
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
529 Zcols = any (Zfinite, 1);
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
530 cmin = find (Zcols, 1, "first");
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
531 cmax = find (Zcols, 1, "last");
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
532
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
533 ## Handle nasty case of all NaNs
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
534 if (isempty (rmin))
21385
89fa0694aa2e Fix check-missing-semicolon QA target (bug #47277).
Rik <rik@octave.org>
parents: 20852
diff changeset
535 rmin = 1; rmax = rows (Z);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
536 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
537 if (isempty (cmin))
21385
89fa0694aa2e Fix check-missing-semicolon QA target (bug #47277).
Rik <rik@octave.org>
parents: 20852
diff changeset
538 cmin = 1; cmax = columns (Z);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
539 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
540
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
541 if ( ! any (isnan (Z([rmin, rmax],:)(:)))
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
542 && ! any (isnan (Z(:, [cmin, cmax])(:))))
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
543 ## Exclude surfaces along borders which are flat (gradient =~ 0).
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
544 ## Technically, this calculation might be better done with actual
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
545 ## deltaX, deltaY values. But, data is usually meshgridded
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
546 ## (constant spacing) so working with deltaROW#, deltaCOL# is fine.
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
547 [Zx, Zy] = gradient (Z(rmin:rmax, cmin:cmax));
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
548 Zgrad = sqrt (Zx.^2 + Zy.^2);
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
549 slope = ((max (Z(:)) - min (Z(:)))
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
550 / sqrt ((rmax - rmin)^2 + (cmax - cmin)^2));
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
551 slope /= 125; # threshold for discarding points.
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
552 Zrows = any (Zgrad > slope, 2);
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
553 rmin += find (Zrows, 1, "first") - 1;
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
554 rmax += find (Zrows, 1, "last") - rows (Zrows);
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
555 Zcols = any (Zgrad > slope, 1);
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
556 cmin += find (Zcols, 1, "first") - 1;
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
557 cmax += find (Zcols, 1, "last") - columns (Zcols);
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
558 endif
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
559
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
560 domain = [X(1,cmin) X(1,cmax) Y(rmin,1) Y(rmax,1)];
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
561 endif
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
562
16993
78f57b14535c Overhaul ez* family of plot functions.
Rik <rik@octave.org>
parents: 14868
diff changeset
563 endfunction