Mercurial > hg > octave-nkf
annotate doc/interpreter/plotimages.m @ 10809:85cbd239fce2
try a better status bar for fltk backend
author | Shai Ayal <shaiay@users.sourceforge.net> |
---|---|
date | Tue, 20 Jul 2010 19:31:17 +0300 |
parents | e76d8c767584 |
children | d9c8916bb9dd |
rev | line source |
---|---|
9245 | 1 ## Copyright (C) 2007, 2008, 2009 John W. Eaton and David Bateman |
7018 | 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) |
9088
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
20 set_print_size (); |
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
21 hide_output (); |
7257 | 22 if (strcmp (typ, "png")) |
23 set (0, "defaulttextfontname", "*"); | |
24 endif | |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
25 if (strcmp (typ, "eps")) |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
26 d_typ = "-depsc2"; |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
27 else |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
28 d_typ = cstrcat ("-d", typ); |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
29 endif |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
30 |
7256 | 31 if (strcmp(typ , "txt")) |
32 image_as_txt(nm); | |
33 elseif (strcmp (nm, "plot")) | |
6888 | 34 x = -10:0.1:10; |
35 plot (x, sin (x)); | |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
36 print (cstrcat (nm, ".", typ), d_typ) |
6888 | 37 elseif (strcmp (nm, "hist")) |
9298
20ee7f9cc904
Correct bugs in plot images produced for documentation
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
38 rand ("state", 2); |
6888 | 39 hist (randn (10000, 1), 30); |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
40 print (cstrcat (nm, ".", typ), d_typ) |
6888 | 41 elseif (strcmp (nm, "errorbar")) |
9298
20ee7f9cc904
Correct bugs in plot images produced for documentation
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
42 rand ("state", 2); |
6888 | 43 x = 0:0.1:10; |
44 y = sin (x); | |
9298
20ee7f9cc904
Correct bugs in plot images produced for documentation
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
45 yl = 0.1 .* rand (size (x)); |
20ee7f9cc904
Correct bugs in plot images produced for documentation
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
46 yu = 0.1 .* rand (size (x)); |
20ee7f9cc904
Correct bugs in plot images produced for documentation
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
47 errorbar (x, sin (x), yl, yu); |
20ee7f9cc904
Correct bugs in plot images produced for documentation
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
48 axis ([0, 10, -1.1, 1.1]); |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
49 print (cstrcat (nm, ".", typ), d_typ) |
6888 | 50 elseif (strcmp (nm, "polar")) |
51 polar (0:0.1:10*pi, 0:0.1:10*pi); | |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
52 print (cstrcat (nm, ".", typ), d_typ) |
6888 | 53 elseif (strcmp (nm, "mesh")) |
54 tx = ty = linspace (-8, 8, 41)'; | |
55 [xx, yy] = meshgrid (tx, ty); | |
56 r = sqrt (xx .^ 2 + yy .^ 2) + eps; | |
57 tz = sin (r) ./ r; | |
58 mesh (tx, ty, tz); | |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
59 print (cstrcat (nm, ".", typ), d_typ) |
6888 | 60 elseif (strcmp (nm, "plot3")) |
61 t = 0:0.1:10*pi; | |
62 r = linspace (0, 1, numel (t)); | |
63 z = linspace (0, 1, numel (t)); | |
64 plot3 (r.*sin(t), r.*cos(t), z); | |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
65 print (cstrcat (nm, ".", typ), d_typ) |
7189 | 66 elseif (strcmp (nm, "extended")) |
67 x = 0:0.01:3; | |
68 plot(x,erf(x)); | |
69 hold on; | |
70 plot(x,x,"r"); | |
71 axis([0, 3, 0, 1]); | |
7540
3422f39573b1
strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
Ben Abbott <bpabbott@mac.com>
parents:
7257
diff
changeset
|
72 text(0.65, 0.6175, cstrcat('\leftarrow x = {2/\surd\pi {\fontsize{16}', |
7189 | 73 '\int_{\fontsize{8}0}^{\fontsize{8}x}} e^{-t^2} dt} = 0.6175')) |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
74 print (cstrcat (nm, ".", typ), d_typ) |
6888 | 75 else |
76 error ("unrecognized plot requested"); | |
77 endif | |
9088
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
78 hide_output (); |
6888 | 79 endfunction |
80 | |
9088
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
81 function set_print_size () |
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
82 image_size = [5.0, 3.5]; # in inches, 16:9 format |
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
83 border = 0; # For postscript use 50/72 |
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
84 set (0, "defaultfigurepapertype", "<custom>"); |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
85 set (0, "defaultfigurepaperorientation", "landscape"); |
9088
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
86 set (0, "defaultfigurepapersize", image_size + 2*border); |
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
87 set (0, "defaultfigurepaperposition", [border, border, image_size]); |
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
88 endfunction |
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
89 |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
90 ## Use this function before plotting commands and after every call to |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
91 ## print since print() resets output to stdout (unfortunately, gnpulot |
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
92 ## can't pop output as it can the terminal type). |
9088
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
93 function hide_output () |
6888 | 94 f = figure (1); |
95 set (f, "visible", "off"); | |
96 endfunction | |
7256 | 97 |
98 ## generate something for the texinfo @image command to process | |
99 function image_as_txt(nm) | |
100 fid = fopen (sprintf ("%s.txt", nm), "wt"); | |
101 fputs (fid, "\n"); | |
102 fputs (fid, "+---------------------------------+\n"); | |
103 fputs (fid, "| Image unavailable in text mode. |\n"); | |
104 fputs (fid, "+---------------------------------+\n"); | |
105 fclose (fid); | |
106 endfunction |