Mercurial > octave
annotate doc/interpreter/interpimages.m @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
1 ## Copyright (C) 2007-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27847
diff
changeset
|
2 ## |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27847
diff
changeset
|
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27847
diff
changeset
|
4 ## or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27847
diff
changeset
|
5 ## |
7018 | 6 ## |
7 ## This file is part of Octave. | |
8 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24462
diff
changeset
|
9 ## Octave is free software: you can redistribute it and/or modify it |
7018 | 10 ## 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:
24462
diff
changeset
|
11 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
12 ## (at your option) any later version. |
7018 | 13 ## |
14 ## Octave is distributed in the hope that it will be useful, but | |
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## GNU General Public License for more details. |
7018 | 18 ## |
19 ## You should have received a copy of the GNU General Public License | |
20 ## 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:
24462
diff
changeset
|
21 ## <https://www.gnu.org/licenses/>. |
7018 | 22 |
20307
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19717
diff
changeset
|
23 function interpimages (d, nm, typ) |
20335
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
24 set_graphics_toolkit (); |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
25 set_print_size (); |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
26 hide_output (); |
20316
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
27 outfile = fullfile (d, [nm "." typ]); |
7257 | 28 if (strcmp (typ, "png")) |
24462
8ff3c13d14c1
groot.m: New function to return handle of graphics root object.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
29 set (groot, "defaulttextfontname", "*"); |
7257 | 30 endif |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
31 if (strcmp (typ, "eps")) |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
32 d_typ = "-depsc2"; |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
33 else |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
34 d_typ = ["-d", typ]; |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
35 endif |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
36 |
7262 | 37 if (strcmp (typ, "txt")) |
20307
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19717
diff
changeset
|
38 image_as_txt (d, nm); |
7262 | 39 elseif (strcmp (nm, "interpft")) |
6721 | 40 t = 0 : 0.3 : pi; dt = t(2)-t(1); |
41 n = length (t); k = 100; | |
42 ti = t(1) + [0 : k-1]*dt*n/k; | |
43 y = sin (4*t + 0.3) .* cos (3*t - 0.1); | |
44 yp = sin (4*ti + 0.3) .* cos (3*ti - 0.1); | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
45 plot (ti, yp, "g", ti, interp1 (t, y, ti, "spline"), "b", ... |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
46 ti, interpft (y, k), "c", t, y, "r+"); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
47 legend ("sin(4t+0.3)cos(3t-0.1)", "spline", "interpft", "data"); |
20307
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19717
diff
changeset
|
48 print (outfile, d_typ); |
6721 | 49 elseif (strcmp (nm, "interpn")) |
50 x = y = z = -1:1; | |
51 f = @(x,y,z) x.^2 - y - z.^2; | |
52 [xx, yy, zz] = meshgrid (x, y, z); | |
53 v = f (xx,yy,zz); | |
54 xi = yi = zi = -1:0.1:1; | |
55 [xxi, yyi, zzi] = ndgrid (xi, yi, zi); | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
56 vi = interpn (x, y, z, v, xxi, yyi, zzi, "spline"); |
6723 | 57 mesh (zi, yi, squeeze (vi(1,:,:))); |
20307
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19717
diff
changeset
|
58 print (outfile, d_typ); |
6743 | 59 elseif (strcmp (nm, "interpderiv1")) |
60 t = -2:2; | |
61 dt = 1; | |
62 ti =-2:0.025:2; | |
63 dti = 0.025; | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
64 y = sign (t); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
65 ys = interp1 (t,y,ti,"spline"); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
66 yp = interp1 (t,y,ti,"pchip"); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
67 plot (ti, ys,"r-", ti, yp,"g-"); |
26362
e3dfcfc8bd6c
interpimages.m: Replace deprecated use of numeric position argument to legend.
Rik <rik@octave.org>
parents:
25998
diff
changeset
|
68 legend ("spline","pchip", "location", "southeast"); |
20307
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19717
diff
changeset
|
69 print (outfile, d_typ); |
6743 | 70 elseif (strcmp (nm, "interpderiv2")) |
71 t = -2:2; | |
72 dt = 1; | |
73 ti =-2:0.025:2; | |
74 dti = 0.025; | |
17504
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
75 y = sign (t); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
76 ddys = diff (diff (interp1 (t,y,ti,"spline"))./dti)./dti; |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
77 ddyp = diff (diff (interp1 (t,y,ti,"pchip"))./dti)./dti; |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
78 plot (ti(2:end-1),ddys,"r*", ti(2:end-1),ddyp,"g+"); |
8b692d9ea54e
Use Octave coding conventions for m-files which generate images for manual.
Rik <rik@octave.org>
parents:
16994
diff
changeset
|
79 legend ("spline", "pchip"); |
20307
c3c1fb44f9b5
eliminate recursive make invocations in doc directory tree
John W. Eaton <jwe@octave.org>
parents:
19717
diff
changeset
|
80 print (outfile, d_typ); |
6721 | 81 endif |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
82 hide_output (); |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
83 endfunction |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
84 |
20335
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
85 ## This function no longer sets the graphics toolkit; That is now done |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
86 ## automatically by C++ code which will ordinarily choose 'qt', but might |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
87 ## choose gnuplot on older systems. Only a complete lack of plotting is a |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
88 ## problem. |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
89 function set_graphics_toolkit () |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
90 if (isempty (available_graphics_toolkits ())) |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
91 error ("no graphics toolkit available for plotting"); |
24798
45470049a43f
Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24534
diff
changeset
|
92 elseif (strcmp ("qt", graphics_toolkit ()) |
25428
2b3c3c8c8360
Properly test Qt offscreen printing during manual figures generation.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25054
diff
changeset
|
93 && __have_feature__ ("QT_OFFSCREEN")) |
24798
45470049a43f
Allow getframe and print to work without osmesa (bug #53186).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
24534
diff
changeset
|
94 ## Use qt with QOffscreenSurface for plot |
27847
56d94f86a659
Don't test presence of OSMESA which will always fail (bug #57424)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
26376
diff
changeset
|
95 elseif (! strcmp ("gnuplot", graphics_toolkit ())) |
20885
e5f78891ad9e
Allow doc's images to be generated using gnuplot when osmesa isn't available.
Ben Abbott <bpabbott@mac.com>
parents:
20335
diff
changeset
|
96 if (! any (strcmp ("gnuplot", available_graphics_toolkits ()))) |
e5f78891ad9e
Allow doc's images to be generated using gnuplot when osmesa isn't available.
Ben Abbott <bpabbott@mac.com>
parents:
20335
diff
changeset
|
97 error ("no graphics toolkit available for offscreen plotting"); |
e5f78891ad9e
Allow doc's images to be generated using gnuplot when osmesa isn't available.
Ben Abbott <bpabbott@mac.com>
parents:
20335
diff
changeset
|
98 else |
e5f78891ad9e
Allow doc's images to be generated using gnuplot when osmesa isn't available.
Ben Abbott <bpabbott@mac.com>
parents:
20335
diff
changeset
|
99 graphics_toolkit ("gnuplot"); |
e5f78891ad9e
Allow doc's images to be generated using gnuplot when osmesa isn't available.
Ben Abbott <bpabbott@mac.com>
parents:
20335
diff
changeset
|
100 endif |
20335
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
101 endif |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
102 endfunction |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
103 |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
104 function set_print_size () |
25998
8d2b3e3ff182
print.m: Implement "-opengl", "-painters" and "-RGBImage" options (bug #52866)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
25428
diff
changeset
|
105 image_size = [5.0, 3.5]; # in inches, 16:9 format |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
106 border = 0; # For postscript use 50/72 |
24462
8ff3c13d14c1
groot.m: New function to return handle of graphics root object.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
107 set (groot, "defaultfigurepapertype", "<custom>"); |
8ff3c13d14c1
groot.m: New function to return handle of graphics root object.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
108 set (groot, "defaultfigurepaperorientation", "landscape"); |
8ff3c13d14c1
groot.m: New function to return handle of graphics root object.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
109 set (groot, "defaultfigurepapersize", image_size + 2*border); |
8ff3c13d14c1
groot.m: New function to return handle of graphics root object.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
110 set (groot, "defaultfigurepaperposition", [border, border, image_size]); |
22037
782ecfde4859
doc: Create images for manual with legends that don't extend out of axes box.
Rik <rik@octave.org>
parents:
21226
diff
changeset
|
111 ## FIXME: Required until listener for legend exists (bug #39697) |
24462
8ff3c13d14c1
groot.m: New function to return handle of graphics root object.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
112 set (groot, "defaultfigureposition", [ 72*[border, border, image_size] ]); |
6721 | 113 endfunction |
114 | |
20335
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
115 ## Use this function before plotting commands and after every call to print |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
116 ## since print() resets output to stdout (unfortunately, gnuplot can't pop |
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
117 ## output as it can the terminal type). |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
118 function hide_output () |
20335
b439ccc9a162
doc: Improve building of images for the Manual.
Rik <rik@octave.org>
parents:
20316
diff
changeset
|
119 hf = figure (1, "visible", "off"); |
6721 | 120 endfunction |
7262 | 121 |
122 ## generate something for the texinfo @image command to process | |
20316
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
123 function image_as_txt (d, nm) |
d8992a16643c
doc: Clean up m-files which generate images for Manual.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
124 fid = fopen (fullfile (d, [nm ".txt"]), "wt"); |
7262 | 125 fputs (fid, "\n"); |
126 fputs (fid, "+---------------------------------+\n"); | |
127 fputs (fid, "| Image unavailable in text mode. |\n"); | |
128 fputs (fid, "+---------------------------------+\n"); | |
129 fclose (fid); | |
130 endfunction |