7018
|
1 ## Copyright (C) 2007 John W. Eaton and David Bateman |
|
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 |
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
|
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 |
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
|
18 |
6888
|
19 function plotimages (nm, typ) |
|
20 bury_output (); |
7256
|
21 if (strcmp(typ , "txt")) |
|
22 image_as_txt(nm); |
|
23 elseif (strcmp (nm, "plot")) |
6888
|
24 x = -10:0.1:10; |
|
25 plot (x, sin (x)); |
|
26 print (strcat (nm, ".", typ), strcat ("-d", typ)) |
|
27 elseif (strcmp (nm, "hist")) |
|
28 hist (randn (10000, 1), 30); |
|
29 print (strcat (nm, ".", typ), strcat ("-d", typ)) |
|
30 elseif (strcmp (nm, "errorbar")) |
|
31 x = 0:0.1:10; |
|
32 y = sin (x); |
|
33 yp = 0.1 .* randn (size (x)); |
|
34 ym = -0.1 .* randn (size (x)); |
|
35 errorbar (x, sin (x), ym, yp); |
|
36 print (strcat (nm, ".", typ), strcat ("-d", typ)) |
|
37 elseif (strcmp (nm, "polar")) |
|
38 polar (0:0.1:10*pi, 0:0.1:10*pi); |
|
39 print (strcat (nm, ".", typ), strcat ("-d", typ)) |
|
40 elseif (strcmp (nm, "mesh")) |
|
41 tx = ty = linspace (-8, 8, 41)'; |
|
42 [xx, yy] = meshgrid (tx, ty); |
|
43 r = sqrt (xx .^ 2 + yy .^ 2) + eps; |
|
44 tz = sin (r) ./ r; |
|
45 mesh (tx, ty, tz); |
|
46 print (strcat (nm, ".", typ), strcat ("-d", typ)) |
|
47 elseif (strcmp (nm, "plot3")) |
|
48 t = 0:0.1:10*pi; |
|
49 r = linspace (0, 1, numel (t)); |
|
50 z = linspace (0, 1, numel (t)); |
|
51 plot3 (r.*sin(t), r.*cos(t), z); |
|
52 print (strcat (nm, ".", typ), strcat ("-d", typ)) |
7189
|
53 elseif (strcmp (nm, "extended")) |
|
54 x = 0:0.01:3; |
|
55 plot(x,erf(x)); |
|
56 hold on; |
|
57 plot(x,x,"r"); |
|
58 axis([0, 3, 0, 1]); |
|
59 text(0.65, 0.6175, strcat('\leftarrow x = {2/\surd\pi {\fontsize{16}', |
|
60 '\int_{\fontsize{8}0}^{\fontsize{8}x}} e^{-t^2} dt} = 0.6175')) |
|
61 print (strcat (nm, ".", typ), strcat ("-d", typ)) |
6888
|
62 else |
|
63 error ("unrecognized plot requested"); |
|
64 endif |
|
65 bury_output (); |
|
66 endfunction |
|
67 |
|
68 function bury_output () |
|
69 f = figure (1); |
|
70 set (f, "visible", "off"); |
|
71 endfunction |
7256
|
72 |
|
73 ## generate something for the texinfo @image command to process |
|
74 function image_as_txt(nm) |
|
75 fid = fopen (sprintf ("%s.txt", nm), "wt"); |
|
76 fputs (fid, "\n"); |
|
77 fputs (fid, "+---------------------------------+\n"); |
|
78 fputs (fid, "| Image unavailable in text mode. |\n"); |
|
79 fputs (fid, "+---------------------------------+\n"); |
|
80 fclose (fid); |
|
81 endfunction |