Mercurial > octave-nkf
comparison doc/interpreter/plotimages.m @ 20350:b9d4ccf4291c
Use FLTK for creating plots for Manual.
* plot.txi: Add explanation of standalone printing modes to work around
lack of 'interpreter' property for OpenGL toolkits.
* plotimages.m: Rework example using text and 'interpreter' to use
standalone printing.
author | Michael D. Godfrey <michaeldgodfrey@gmail.com> |
---|---|
date | Tue, 07 Jul 2015 21:25:31 +0100 |
parents | c3c1fb44f9b5 |
children | d8992a16643c |
comparison
equal
deleted
inserted
replaced
20348:9e361ecea878 | 20350:b9d4ccf4291c |
---|---|
15 ## You should have received a copy of the GNU General Public License | 15 ## You should have received a copy of the GNU General Public License |
16 ## along with Octave; see the file COPYING. If not, see | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | 17 ## <http://www.gnu.org/licenses/>. |
18 | 18 |
19 function plotimages (d, nm, typ) | 19 function plotimages (d, nm, typ) |
20 graphics_toolkit ("gnuplot"); | 20 graphics_toolkit ("qt"); |
21 set_print_size (); | 21 set_print_size (); |
22 hide_output (); | 22 hide_output (); |
23 outfile = fullfile (d, strcat (nm, ".", typ)); | 23 outfile = fullfile (d, strcat (nm, ".", typ)); |
24 if (strcmp (typ, "png")) | 24 if (strcmp (typ, "png")) |
25 set (0, "defaulttextfontname", "*"); | 25 set (0, "defaulttextfontname", "*"); |
29 else | 29 else |
30 d_typ = ["-d", typ]; | 30 d_typ = ["-d", typ]; |
31 endif | 31 endif |
32 | 32 |
33 if (strcmp(typ , "txt")) | 33 if (strcmp(typ , "txt")) |
34 image_as_txt(d, nm); | 34 image_as_txt (d, nm); |
35 elseif (strcmp (nm, "plot")) | 35 elseif (strcmp (nm, "plot")) |
36 x = -10:0.1:10; | 36 x = -10:0.1:10; |
37 plot (x, sin (x)); | 37 plot (x, sin (x)); |
38 xlabel ("x"); | 38 xlabel ("x"); |
39 ylabel ("sin (x)"); | 39 ylabel ("sin (x)"); |
58 ylabel ("sin (x)"); | 58 ylabel ("sin (x)"); |
59 title ("Errorbar plot of sin (x)"); | 59 title ("Errorbar plot of sin (x)"); |
60 print (outfile, d_typ); | 60 print (outfile, d_typ); |
61 elseif (strcmp (nm, "polar")) | 61 elseif (strcmp (nm, "polar")) |
62 polar (0:0.1:10*pi, 0:0.1:10*pi); | 62 polar (0:0.1:10*pi, 0:0.1:10*pi); |
63 set (gca, "rtick", [0:10:40]); | |
63 title ("Example polar plot from 0 to 10*pi"); | 64 title ("Example polar plot from 0 to 10*pi"); |
64 print (outfile, d_typ); | 65 print (outfile, d_typ); |
65 elseif (strcmp (nm, "mesh")) | 66 elseif (strcmp (nm, "mesh")) |
66 tx = ty = linspace (-8, 8, 41)'; | 67 tx = ty = linspace (-8, 8, 41)'; |
67 [xx, yy] = meshgrid (tx, ty); | 68 [xx, yy] = meshgrid (tx, ty); |
83 zlabel ("z"); | 84 zlabel ("z"); |
84 title ("plot3 display of 3-D helix"); | 85 title ("plot3 display of 3-D helix"); |
85 print (outfile, d_typ); | 86 print (outfile, d_typ); |
86 elseif (strcmp (nm, "extended")) | 87 elseif (strcmp (nm, "extended")) |
87 x = 0:0.01:3; | 88 x = 0:0.01:3; |
88 plot (x,erf(x)); | 89 plot (x, erf (x)); |
89 hold on; | 90 hold on; |
90 plot (x,x,"r"); | 91 plot (x, x, "r"); |
91 axis ([0, 3, 0, 1]); | 92 axis ([0, 3, 0, 1]); |
92 text (0.65, 0.6175, ['\leftarrow x = {2/\surd\pi {\fontsize{16}' ... | 93 if (strcmp (typ, "pdf")) |
93 '\int_{\fontsize{8}0}^{\fontsize{8}x}} e^{-t^2} dt} = 0.6175']); | 94 text (0.65, 0.6175, ['$\leftarrow x = {2/\sqrt{\pi}' ... |
95 '{\int_{0}^{x}}e^{-t^2} dt} = 0.6175$']); | |
96 else | |
97 text (0.65, 0.6175, ['\leftarrow x = {2/\surd\pi {\fontsize{16}' ... | |
98 '\int_{\fontsize{8}0}^{\fontsize{8}x}} e^{-t^2} dt} = 0.6175']); | |
99 endif | |
94 xlabel ("x"); | 100 xlabel ("x"); |
95 ylabel ("erf (x)"); | 101 ylabel ("erf (x)"); |
96 title ("erf (x) with text annotation"); | 102 title ("erf (x) with text annotation"); |
97 print (outfile, d_typ); | 103 if (strcmp (typ, "pdf")) |
104 print ([nm ".pdf"], "-dpdflatexstandalone"); | |
105 system (["pdflatex " nm]); | |
106 delete ([nm ".aux"], [nm "-inc.pdf"], [nm ".log"], [nm ".tex"]); | |
107 else | |
108 print ([nm "." typ], d_typ); | |
109 endif | |
98 else | 110 else |
99 error ("unrecognized plot requested"); | 111 error ("unrecognized plot requested"); |
100 endif | 112 endif |
101 hide_output (); | 113 hide_output (); |
102 endfunction | 114 endfunction |
109 set (0, "defaultfigurepapersize", image_size + 2*border); | 121 set (0, "defaultfigurepapersize", image_size + 2*border); |
110 set (0, "defaultfigurepaperposition", [border, border, image_size]); | 122 set (0, "defaultfigurepaperposition", [border, border, image_size]); |
111 endfunction | 123 endfunction |
112 | 124 |
113 ## Use this function before plotting commands and after every call to | 125 ## Use this function before plotting commands and after every call to |
114 ## print since print() resets output to stdout (unfortunately, gnpulot | 126 ## print since print() resets output to stdout (unfortunately, gnuplot |
115 ## can't pop output as it can the terminal type). | 127 ## can't pop output as it can the terminal type). |
116 function hide_output () | 128 function hide_output () |
117 f = figure (1); | 129 f = figure (1); |
118 set (f, "visible", "off"); | 130 set (f, "visible", "off"); |
119 endfunction | 131 endfunction |
120 | 132 |
121 ## generate something for the texinfo @image command to process | 133 ## generate something for the texinfo @image command to process |
122 function image_as_txt(d, nm) | 134 function image_as_txt (d, nm) |
123 fid = fopen (fullfile (d, strcat (nm, ".txt")), "wt"); | 135 fid = fopen (fullfile (d, strcat (nm, ".txt")), "wt"); |
124 fputs (fid, "\n"); | 136 fputs (fid, "\n"); |
125 fputs (fid, "+---------------------------------+\n"); | 137 fputs (fid, "+---------------------------------+\n"); |
126 fputs (fid, "| Image unavailable in text mode. |\n"); | 138 fputs (fid, "| Image unavailable in text mode. |\n"); |
127 fputs (fid, "+---------------------------------+\n"); | 139 fputs (fid, "+---------------------------------+\n"); |