Mercurial > hg > octave-lyh
annotate scripts/plot/fplot.m @ 14237:11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Add clf() to all demos using plot features to get reproducibility.
Use 64 as input to all colormaps (jet (64)) to get reproducibility.
* bicubic.m, cell2mat.m, celldisp.m, cplxpair.m, interp1.m, interp2.m,
interpft.m, interpn.m, profile.m, profshow.m, convhull.m, delaunay.m,
griddata.m, inpolygon.m, voronoi.m, autumn.m, bone.m, contrast.m, cool.m,
copper.m, flag.m, gmap40.m, gray.m, hot.m, hsv.m, image.m, imshow.m, jet.m,
ocean.m, pink.m, prism.m, rainbow.m, spring.m, summer.m, white.m, winter.m,
condest.m, onenormest.m, axis.m, clabel.m, colorbar.m, comet.m, comet3.m,
compass.m, contour.m, contour3.m, contourf.m, cylinder.m, daspect.m,
ellipsoid.m, errorbar.m, ezcontour.m, ezcontourf.m, ezmesh.m, ezmeshc.m,
ezplot.m, ezplot3.m, ezpolar.m, ezsurf.m, ezsurfc.m, feather.m, fill.m,
fplot.m, grid.m, hold.m, isosurface.m, legend.m, loglog.m, loglogerr.m,
pareto.m, patch.m, pbaspect.m, pcolor.m, pie.m, pie3.m, plot3.m, plotmatrix.m,
plotyy.m, polar.m, quiver.m, quiver3.m, rectangle.m, refreshdata.m, ribbon.m,
rose.m, scatter.m, scatter3.m, semilogx.m, semilogxerr.m, semilogy.m,
semilogyerr.m, shading.m, slice.m, sombrero.m, stairs.m, stem.m, stem3.m,
subplot.m, surf.m, surfc.m, surfl.m, surfnorm.m, text.m, title.m, trimesh.m,
triplot.m, trisurf.m, uigetdir.m, uigetfile.m, uimenu.m, uiputfile.m,
waitbar.m, xlim.m, ylim.m, zlim.m, mkpp.m, pchip.m, polyaffine.m, spline.m,
bicgstab.m, cgs.m, gplot.m, pcg.m, pcr.m, treeplot.m, strtok.m, demo.m,
example.m, rundemos.m, speed.m, test.m, calendar.m, datestr.m, datetick.m,
weekday.m: Revamp %!demos to use Octave coding conventions on spacing, etc.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Fri, 20 Jan 2012 12:59:53 -0800 |
parents | 72c96de7a403 |
children | 4506eade9f04 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14092
diff
changeset
|
1 ## Copyright (C) 2005-2012 Paul Kienzle |
5820 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
5820 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5820 | 18 |
19 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
20 ## @deftypefn {Function File} {} fplot (@var{fn}, @var{limits}) |
6781 | 21 ## @deftypefnx {Function File} {} fplot (@var{fn}, @var{limits}, @var{tol}) |
5820 | 22 ## @deftypefnx {Function File} {} fplot (@var{fn}, @var{limits}, @var{n}) |
6895 | 23 ## @deftypefnx {Function File} {} fplot (@dots{}, @var{fmt}) |
12632
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
24 ## Plot a function @var{fn} within defined limits. |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
25 ## @var{fn} is a function handle, inline function, or string |
2dbac27e0e40
doc: miscellaneous touch-ups to documentation strings
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
26 ## containing the name of the function to evaluate. |
5820 | 27 ## The limits of the plot are given by @var{limits} of the form |
28 ## @code{[@var{xlo}, @var{xhi}]} or @code{[@var{xlo}, @var{xhi}, | |
9040
dbd0c77e575e
Cleanup documentation file plot.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
29 ## @var{ylo}, @var{yhi}]}. @var{tol} is the default tolerance to use for the |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
30 ## plot, and if @var{tol} is an integer it is assumed that it defines the |
6895 | 31 ## number points to use in the plot. The @var{fmt} argument is passed |
32 ## to the plot command. | |
5820 | 33 ## |
34 ## @example | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
9040
diff
changeset
|
35 ## @group |
6699 | 36 ## fplot ("cos", [0, 2*pi]) |
37 ## fplot ("[cos(x), sin(x)]", [0, 2*pi]) | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
9040
diff
changeset
|
38 ## @end group |
5820 | 39 ## @end example |
6781 | 40 ## @seealso{plot} |
5820 | 41 ## @end deftypefn |
42 | |
7017 | 43 ## Author: Paul Kienzle <pkienzle@users.sf.net> |
44 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
45 function fplot (fn, limits, n, fmt) |
8847 | 46 if (nargin < 2 || nargin > 4) |
6046 | 47 print_usage (); |
5820 | 48 endif |
49 | |
10400
b14fd5116c29
Ensure that 'limits' is a 2 or 4 vector, and that 'fn' is a function
Soren Hauberg <hauberg@gmail.com>
parents:
9051
diff
changeset
|
50 if (!isreal (limits) || (numel (limits) != 2 && numel (limits) != 4)) |
b14fd5116c29
Ensure that 'limits' is a 2 or 4 vector, and that 'fn' is a function
Soren Hauberg <hauberg@gmail.com>
parents:
9051
diff
changeset
|
51 error ("fplot: second input argument must be a real vector with 2 or 4 elements"); |
b14fd5116c29
Ensure that 'limits' is a 2 or 4 vector, and that 'fn' is a function
Soren Hauberg <hauberg@gmail.com>
parents:
9051
diff
changeset
|
52 endif |
b14fd5116c29
Ensure that 'limits' is a 2 or 4 vector, and that 'fn' is a function
Soren Hauberg <hauberg@gmail.com>
parents:
9051
diff
changeset
|
53 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
54 if (nargin < 3) |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
55 n = 0.002; |
5820 | 56 endif |
57 | |
6781 | 58 have_linespec = true; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
59 if (nargin < 4) |
6781 | 60 have_linespec = false; |
61 endif | |
5820 | 62 |
6781 | 63 if (ischar (n)) |
64 have_linespec = true; | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
65 fmt = n; |
6781 | 66 n = 0.002; |
67 endif | |
68 | |
6699 | 69 if (strcmp (typeinfo (fn), "inline function")) |
70 fn = vectorize (fn); | |
71 nam = formula (fn); | |
72 elseif (isa (fn, "function_handle")) | |
73 nam = func2str (fn); | |
5820 | 74 elseif (all (isalnum (fn))) |
6781 | 75 nam = fn; |
10400
b14fd5116c29
Ensure that 'limits' is a 2 or 4 vector, and that 'fn' is a function
Soren Hauberg <hauberg@gmail.com>
parents:
9051
diff
changeset
|
76 elseif (ischar (fn)) |
b14fd5116c29
Ensure that 'limits' is a 2 or 4 vector, and that 'fn' is a function
Soren Hauberg <hauberg@gmail.com>
parents:
9051
diff
changeset
|
77 fn = vectorize (inline (fn)); |
b14fd5116c29
Ensure that 'limits' is a 2 or 4 vector, and that 'fn' is a function
Soren Hauberg <hauberg@gmail.com>
parents:
9051
diff
changeset
|
78 nam = formula (fn); |
5820 | 79 else |
10400
b14fd5116c29
Ensure that 'limits' is a 2 or 4 vector, and that 'fn' is a function
Soren Hauberg <hauberg@gmail.com>
parents:
9051
diff
changeset
|
80 error ("fplot: first input argument must be a function handle, inline function or string"); |
6781 | 81 endif |
82 | |
83 if (floor(n) != n) | |
84 tol = n; | |
7280 | 85 x0 = linspace (limits(1), limits(2), 5)'; |
6781 | 86 y0 = feval (fn, x0); |
87 err0 = Inf; | |
7280 | 88 n = 8; |
6781 | 89 x = linspace (limits(1), limits(2), n)'; |
90 y = feval (fn, x); | |
91 | |
92 while (n < 2 .^ 20) | |
93 y00 = interp1 (x0, y0, x, "linear"); | |
94 err = 0.5 * max (abs ((y00 - y) ./ (y00 + y))(:)); | |
95 if (err == err0 || 0.5 * max (abs ((y00 - y) ./ (y00 + y))(:)) < tol) | |
10549 | 96 break; |
6781 | 97 endif |
98 x0 = x; | |
99 y0 = y; | |
100 err0 = err; | |
101 n = 2 * (n - 1) + 1; | |
102 x = linspace (limits(1), limits(2), n)'; | |
103 y = feval (fn, x); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
104 endwhile |
6781 | 105 else |
106 x = linspace (limits(1), limits(2), n)'; | |
107 y = feval (fn, x); | |
5820 | 108 endif |
109 | |
6781 | 110 if (have_linespec) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
111 plot (x, y, fmt); |
6781 | 112 else |
113 plot (x, y); | |
114 endif | |
8145
7ef5b1b4e029
fplot.m: call axis after plot
John W. Eaton <jwe@octave.org>
parents:
7280
diff
changeset
|
115 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
116 if (length (limits) > 2) |
8145
7ef5b1b4e029
fplot.m: call axis after plot
John W. Eaton <jwe@octave.org>
parents:
7280
diff
changeset
|
117 axis (limits); |
7ef5b1b4e029
fplot.m: call axis after plot
John W. Eaton <jwe@octave.org>
parents:
7280
diff
changeset
|
118 endif |
7ef5b1b4e029
fplot.m: call axis after plot
John W. Eaton <jwe@octave.org>
parents:
7280
diff
changeset
|
119 |
8507 | 120 if (isvector (y)) |
6781 | 121 legend (nam); |
122 else | |
8507 | 123 for i = 1:columns (y) |
6781 | 124 nams{i} = sprintf ("%s(:,%i)", nam, i); |
125 endfor | |
126 legend (nams{:}); | |
127 endif | |
5820 | 128 endfunction |
7245 | 129 |
130 | |
131 %!demo | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
132 %! clf; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
133 %! fplot ("cos", [0, 2*pi]); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
134 |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
135 %!demo |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
136 %! clf; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
137 %! fplot ("[cos(x), sin(x)]", [0, 2*pi]); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
138 |