Mercurial > octave-nkf
annotate doc/interpreter/plotimages.m @ 17744:d63878346099
maint: Update copyright notices for release.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 23 Oct 2013 22:09:27 -0400 |
parents | 7babcdb9bc13 |
children | 4197fc428c7d |
rev | line source |
---|---|
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17245
diff
changeset
|
1 ## Copyright (C) 2007-2013 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) |
11576
8ac9687dbe9f
rename backend to graphics_toolkit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
20 graphics_toolkit ("gnuplot"); |
9088
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
21 set_print_size (); |
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
22 hide_output (); |
7257 | 23 if (strcmp (typ, "png")) |
24 set (0, "defaulttextfontname", "*"); | |
25 endif | |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
26 if (strcmp (typ, "eps")) |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
27 d_typ = "-depsc2"; |
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
28 else |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
29 d_typ = ["-d", typ]; |
9914
e76d8c767584
Switch to color output for PostScript documentation images
Rik <rdrider0-list@yahoo.com>
parents:
9912
diff
changeset
|
30 endif |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
31 |
7256 | 32 if (strcmp(typ , "txt")) |
33 image_as_txt(nm); | |
34 elseif (strcmp (nm, "plot")) | |
6888 | 35 x = -10:0.1:10; |
36 plot (x, sin (x)); | |
17166
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
37 xlabel ("x"); |
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
38 ylabel ("sin (x)"); |
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
39 title ("Simple 2-D Plot"); |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
40 print ([nm "." typ], d_typ); |
6888 | 41 elseif (strcmp (nm, "hist")) |
11033
d9c8916bb9dd
Untabify a few remaining .m scripts.
Rik <octave@nomad.inbox5.com>
parents:
9914
diff
changeset
|
42 rand ("state", 2); |
6888 | 43 hist (randn (10000, 1), 30); |
17166
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
44 xlabel ("Value"); |
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
45 ylabel ("Count"); |
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
46 title ("Histogram of 10,000 normally distributed random numbers"); |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
47 print ([nm "." typ], d_typ); |
6888 | 48 elseif (strcmp (nm, "errorbar")) |
11033
d9c8916bb9dd
Untabify a few remaining .m scripts.
Rik <octave@nomad.inbox5.com>
parents:
9914
diff
changeset
|
49 rand ("state", 2); |
6888 | 50 x = 0:0.1:10; |
51 y = sin (x); | |
9298
20ee7f9cc904
Correct bugs in plot images produced for documentation
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
52 yl = 0.1 .* rand (size (x)); |
20ee7f9cc904
Correct bugs in plot images produced for documentation
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
53 yu = 0.1 .* rand (size (x)); |
20ee7f9cc904
Correct bugs in plot images produced for documentation
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
54 errorbar (x, sin (x), yl, yu); |
11033
d9c8916bb9dd
Untabify a few remaining .m scripts.
Rik <octave@nomad.inbox5.com>
parents:
9914
diff
changeset
|
55 axis ([0, 10, -1.1, 1.1]); |
17166
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
56 xlabel ("x"); |
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
57 ylabel ("sin (x)"); |
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
58 title ("Errorbar plot of sin (x)"); |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
59 print ([nm "." typ], d_typ); |
6888 | 60 elseif (strcmp (nm, "polar")) |
61 polar (0:0.1:10*pi, 0:0.1:10*pi); | |
17166
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
62 title ("Example polar plot from 0 to 10*pi"); |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
63 print ([nm "." typ], d_typ); |
6888 | 64 elseif (strcmp (nm, "mesh")) |
65 tx = ty = linspace (-8, 8, 41)'; | |
66 [xx, yy] = meshgrid (tx, ty); | |
67 r = sqrt (xx .^ 2 + yy .^ 2) + eps; | |
68 tz = sin (r) ./ r; | |
69 mesh (tx, ty, tz); | |
17166
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
70 xlabel ("tx"); |
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
71 ylabel ("ty"); |
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
72 zlabel ("tz"); |
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
73 title ("3-D Sombrero plot"); |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
74 print ([nm "." typ], d_typ); |
6888 | 75 elseif (strcmp (nm, "plot3")) |
76 t = 0:0.1:10*pi; | |
77 r = linspace (0, 1, numel (t)); | |
78 z = linspace (0, 1, numel (t)); | |
79 plot3 (r.*sin(t), r.*cos(t), z); | |
17166
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
80 xlabel ("r.*sin (t)"); |
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
81 ylabel ("r.*cos (t)"); |
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
82 zlabel ("z"); |
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
83 title ("plot3 display of 3-D helix"); |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
84 print ([nm "." typ], d_typ); |
7189 | 85 elseif (strcmp (nm, "extended")) |
86 x = 0:0.01:3; | |
17166
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
87 plot (x,erf(x)); |
7189 | 88 hold on; |
17166
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
89 plot (x,x,"r"); |
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
90 axis ([0, 3, 0, 1]); |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17166
diff
changeset
|
91 text (0.65, 0.6175, ['\leftarrow x = {2/\surd\pi {\fontsize{16}' ... |
17166
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
92 '\int_{\fontsize{8}0}^{\fontsize{8}x}} e^{-t^2} dt} = 0.6175']); |
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
93 xlabel ("x"); |
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
94 ylabel ("erf (x)"); |
0e34c475c956
plotimages.m: Add axis labels and titles to plots in Manual.
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
16994
diff
changeset
|
95 title ("erf (x) with text annotation"); |
16994
333243133364
Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
96 print ([nm "." typ], d_typ); |
6888 | 97 else |
98 error ("unrecognized plot requested"); | |
99 endif | |
9088
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
100 hide_output (); |
6888 | 101 endfunction |
102 | |
9088
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
103 function set_print_size () |
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
104 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
|
105 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
|
106 set (0, "defaultfigurepapertype", "<custom>"); |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
107 set (0, "defaultfigurepaperorientation", "landscape"); |
9088
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
108 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
|
109 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
|
110 endfunction |
77e71f3da3d6
Fix documentation image printing under new development code
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
111 |
9912
e9fe12c1b0c0
Set default papersize to the desired imagesize
Rik <rdrider0-list@yahoo.com>
parents:
9298
diff
changeset
|
112 ## 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
|
113 ## 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
|
114 ## 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
|
115 function hide_output () |
6888 | 116 f = figure (1); |
117 set (f, "visible", "off"); | |
118 endfunction | |
7256 | 119 |
120 ## generate something for the texinfo @image command to process | |
121 function image_as_txt(nm) | |
122 fid = fopen (sprintf ("%s.txt", nm), "wt"); | |
123 fputs (fid, "\n"); | |
124 fputs (fid, "+---------------------------------+\n"); | |
125 fputs (fid, "| Image unavailable in text mode. |\n"); | |
126 fputs (fid, "+---------------------------------+\n"); | |
127 fclose (fid); | |
128 endfunction |