pk-gplot.tex 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. \section{Gnuplot package}
  2. \begin{Introduction}{GNUPLOT and REDUCE}
  3. The GNUPLOT system provides easy to use graphics output
  4. for curves or surfaces which are defined by
  5. formulas and/or data sets. GNUPLOT supports
  6. a great variety of output devices
  7. such as X-windows, VGA screen, postscript, picTeX.
  8. The REDUCE GNUPLOT package lets one use the GNUPLOT
  9. graphical output directly from inside REDUCE, either for
  10. the interactive display of curves/surfaces or for the production
  11. of pictures on paper.
  12. Note that this package may not be supported on all system
  13. platforms.
  14. For a detailed description you should read the GNUPLOT
  15. system documentation, available together with the GNUPLOT
  16. installation material from several servers by anonymous FTP.
  17. The REDUCE developers thank the GNUPLOT people for their permission
  18. to distribute GNUPLOT together with REDUCE.
  19. \end{Introduction}
  20. \begin{Concept}{Axes names}
  21. Inside REDUCE the choice of variable names for a graph is completely
  22. free. For referring to the GNUPLOT axes the names
  23. X and Y for 2 dimensions, X,Y and Z for 3 dimensions are used
  24. in the usual schoolbook sense independent from the variables of
  25. the REDUCE expression.
  26. \begin{Examples}
  27. plot(w=sin(a),a=(0 .. 10),xlabel="angle",ylabel="sine");
  28. \end{Examples}
  29. \end{Concept}
  30. \begin{Type}{Pointset}
  31. \index{plot}
  32. A curve can be give as set of precomputed points (a polygon)
  33. in 2 or 3 dimensions. Such a point set is a \nameref{list}
  34. of points, where each point is a \nameref{list} 2 (or 3)
  35. numbers. These numbers are interpreted as \name{(x,y)}
  36. (or \name{x,y,z}) coordinates. All points of one set must have
  37. the same dimension.
  38. \begin{Examples}
  39. for i:=2:10 collect{i,factorial(i)};
  40. \end{Examples}
  41. Also a surface in 3d can be given by precomputed points,
  42. but only on a logically orthogonal mesh: the surface is defined
  43. by a list of curves (in 3d) which must have a uniform length.
  44. GNUPLOT then will draw an orthogonal mesh by first drawing the
  45. given lines, and second connecting the 1st point of the 1st curve
  46. with the 1st point of the 2nd curve, that one with the 1st point
  47. of the 3rd curve and so on for all curves and for all indexes.
  48. \end{Type}
  49. \begin{Command}{PLOT}
  50. \index{graphics}\index{plot}
  51. The command \name{plot} is the main entry for drawing a
  52. picture from inside REDUCE.
  53. \begin{Syntax}
  54. \name{plot}\(\meta{spec},\meta{spec},...\)
  55. \end{Syntax}
  56. where \meta{spec} is a \meta{function}, a \meta{range} or an \meta{option}.
  57. \meta{function}:
  58. - an expression depending
  59. on one unknown (e.g. \name{sin(x)} or two unknowns (e.g.
  60. \name{sin(x+y)},
  61. - an equation with a function on its right-hand
  62. side and a single name on its left-hand side (e.g.
  63. \name{z=sin(x+y)} where the name on the left-hand side specifies
  64. the dependent variable.
  65. - a list of functions:
  66. if in 2 dimensions the picture should have more than one
  67. curve the expressions can be given as list (e.g. \name{\{sin(x),cos(x)\}}).
  68. - an equation with zero left or right hand side describing
  69. an implicit curve in two dimensions (e.g. \name{x**3+x*y**3-9x=0}).
  70. - a point set: the graph can be given
  71. as point set in 2 dimensions or a \nameref{pointset} or pointset list
  72. in 3 dimensions.
  73. \meta{range}:
  74. Each dependent and independent variable can be limited
  75. to an interval by an equation where the left-hand side specifies
  76. the variable and the right-hand side defines the \nameref{interval},
  77. e.g. \name{x=( -3 .. 5)}.
  78. If omitted the independent variables
  79. range from -10 to 10 and the dependent variable is limited only
  80. by the precision of the IEEE floating point arithmetic.
  81. \meta{option}:
  82. An option can be an equation equating a variable
  83. and a value (in general a string), or a keyword(GNUPLOT switch).
  84. These have to be included in the gnuplot command arguments directly.
  85. Strings have to be enclosed in
  86. string quotes (see \nameref{string}). Available options are:
  87. \nameref{title}: assign a heading (default: empty)
  88. \nameref{xlabel}: set label for the x axis
  89. \nameref{ylabel}: set label for the y axis
  90. \nameref{zlabel}: set label for the z axis
  91. \nameref{terminal}: select an output device
  92. \nameref{size}: rescale the picture
  93. \nameref{view}: set a viewpoint
  94. \name{(no)}\nameref{contour}: 3d: add contour lines
  95. \name{(no)}\nameref{surface}: 3d: draw surface (default: yes)
  96. \name{(no)}\nameref{hidden3d}: 3d: remove hidden lines (default: no)
  97. \begin{Examples}
  98. plot(cos x);\\
  99. plot(s=sin phi,phi=(-3 .. 3));\\
  100. plot(sin phi,cos phi,phi=(-3 .. 3));\\
  101. plot (cos sqrt(x**2 + y**2),x=(-3 .. 3),y=(-3 .. 3),hidden3d);\\
  102. plot {{0,0},{0,1},{1,1},{0,0},{1,0},{0,1},{0.5,1.5},{1,1},{1,0}};\\
  103. \\
  104. on rounded;\\
  105. w:=for j:=1:200 collect {1/j*sin j,1/j*cos j,j/200}$\\
  106. plot w; \\
  107. \end{Examples}
  108. Additional control of the \name{plot} operation:
  109. \nameref{plotrefine},
  110. \nameref{plot_xmesh}, \nameref{plot_ymesh}, \nameref{trplot},
  111. \nameref{plotkeep}, \nameref{show_grid}.
  112. \end{Command}
  113. \begin{Command}{PLOTRESET}
  114. The command \name{plotreset} closes the current GNUPLOT windows.
  115. The next call to \nameref{plot} will create a new one. \name{plotreset}
  116. can also be used to reset the system status after technical problems.
  117. \begin{Syntax}
  118. \name{plotreset};
  119. \end{Syntax}
  120. \end{Command}
  121. \begin{Variable}{title}
  122. \index{plot}
  123. \nameref{plot} option:
  124. Assign a title to the GNUPLOT graph.
  125. \begin{Syntax}
  126. \name{title} = \meta{string}
  127. \end{Syntax}
  128. \begin{Examples}
  129. title="annual revenue in 1993"\\
  130. \end{Examples}
  131. \end{Variable}
  132. \begin{Variable}{xlabel}
  133. \index{plot}
  134. \nameref{plot} option:
  135. Assign a name to to the x axis (see \nameref{axes names}).
  136. \begin{Syntax}
  137. \name{xlabel} = \meta{string}
  138. \end{Syntax}
  139. \begin{Examples}
  140. xlabel="month"\\
  141. \end{Examples}
  142. \end{Variable}
  143. \begin{Variable}{ylabel}
  144. \index{plot}
  145. \nameref{plot} option:
  146. Assign a name to to the x axis (see \nameref{axes names}).
  147. \begin{Syntax}
  148. \name{ylabel} = \meta{string}
  149. \end{Syntax}
  150. \begin{Examples}
  151. ylabel="million forint"\\
  152. \end{Examples}
  153. \end{Variable}
  154. \begin{Variable}{zlabel}
  155. \index{plot}
  156. \nameref{plot} option:
  157. Assign a name to to the z axis (see \nameref{axes names}).
  158. \begin{Syntax}
  159. \name{zlabel} = \meta{string}
  160. \end{Syntax}
  161. \begin{Examples}
  162. zlabel="local weight"\\
  163. \end{Examples}
  164. \end{Variable}
  165. \begin{Variable}{terminal}
  166. \index{plot}
  167. \nameref{plot} option:
  168. Select a different output device. The possible values here
  169. depend highly on the facilities installed for your GNUPLOT
  170. software.
  171. \begin{Syntax}
  172. \name{terminal} = \meta{string}
  173. \end{Syntax}
  174. \begin{Examples}
  175. terminal="x11"\\
  176. \end{Examples}
  177. \end{Variable}
  178. \begin{Variable}{size}
  179. \index{plot}
  180. \nameref{plot} option:
  181. Rescale the graph (not the window!) in x and y direction.
  182. Default is 1.0 (no rescaling).
  183. \begin{Syntax}
  184. \name{size} = "\meta{sx},\meta{sy}"
  185. \end{Syntax}
  186. where \meta{sx},\meta{sy} are floating point number not too
  187. far from 1.0.
  188. \begin{Examples}
  189. size="0.7,1"\\
  190. \end{Examples}
  191. \end{Variable}
  192. \begin{Variable}{view}
  193. \index{plot}
  194. \nameref{plot} option:
  195. Set a new viewpoint by turning the object around the x and then
  196. around the z axis (see \nameref{axes names}).
  197. \begin{Syntax}
  198. \name{view} = "\meta{sx},\meta{sz}"
  199. \end{Syntax}
  200. where \meta{sx},\meta{sz} are floating point number representing
  201. angles in degrees.
  202. \begin{Examples}
  203. view="30,130"\\
  204. \end{Examples}
  205. \end{Variable}
  206. \begin{Switch}{contour}
  207. \index{plot}
  208. \nameref{plot} option:
  209. If \name{contour} is member of the options for a 3d \nameref{plot}
  210. contour lines are projected to the z=0 plane
  211. (see \nameref{axes names}). The absence of contour lines
  212. can be selected explicitly by including \name{nocontour}. Default
  213. is \name{nocontour}.
  214. \end{Switch}
  215. \begin{Switch}{surface}
  216. \index{plot}
  217. \nameref{plot} option:
  218. If \name{surface} is member of the options for a 3d \nameref{plot}
  219. the surface is drawn. The absence of the surface plotting
  220. can be selected by including \name{nosurface}, e.g. if
  221. only the \nameref{contour} should be visualized. Default is \name{surface}.
  222. \end{Switch}
  223. \begin{Switch}{hidden3d}
  224. \index{plot}
  225. \nameref{plot} option:
  226. If \name{hidden3d} is member of the options for a 3d \nameref{plot}
  227. hidden lines are removed from the picture. Otherwise a
  228. surface is drawn as transparent object. Default is
  229. \name{nohidden3d}. Selecting \name{hidden3d} increases the
  230. computing time substantially.
  231. \end{Switch}
  232. \begin{Switch}{PLOTKEEP}
  233. \index{plot}
  234. Normally all intermediate data sets are deleted after terminating
  235. a plot session. If the switch \name{plotkeep} is set \nameref{on},
  236. the data sets are kept for eventual post processing independent
  237. of REDUCE.
  238. \end{Switch}
  239. \begin{Switch}{PLOTREFINE}
  240. \index{plot}
  241. In general \nameref{plot} tries to generate smooth pictures by evaluating
  242. the functions at interior points until the distances are fine
  243. enough. This can require a lot of computing time if the
  244. single function evaluation is expensive. The refinement is
  245. controlled by the switch \name{plotrefine} which is \nameref{on}
  246. by default. When you turn it \nameref{off} the functions will
  247. be evaluated only at the basic points (see \nameref{plot_xmesh},
  248. \nameref{plot_ymesh}).
  249. \end{Switch}
  250. \begin{Variable}{plot_xmesh}
  251. \index{plot}
  252. The integer value of the global variable \name{plot_xmesh}
  253. defines the number of initial function evaluations in x
  254. direction (see \nameref{axes names}) for \nameref{plot}. For 2d graphs additional
  255. points will be used as long as \nameref{plotrefine} is \name{on}.
  256. For 3d graphs this number defines also the number of mesh lines
  257. orthogonal to the x axis.
  258. \end{Variable}
  259. \begin{Variable}{plot_ymesh}
  260. \index{plot}
  261. The integer value of the global variable \name{plot_ymesh}
  262. defines for 3d \nameref{plot} calls the number of function evaluations in y
  263. direction (see \nameref{axes names}) and the number of mesh lines
  264. orthogonal to the y axis.
  265. \end{Variable}
  266. \begin{Switch}{SHOW_GRID}
  267. \index{plot}
  268. The grid for localizing an implicitly defined curve in \nameref{plot}
  269. consists of triangles. These are computed initially equally distributed
  270. over the x-y plane controlled by \nameref{plot_xmesh}. The grid is
  271. refined adaptively in several levels. The final grid can be visualized
  272. by setting on the switch \name{show_grid}.
  273. \end{Switch}
  274. \begin{Switch}{TRPLOT}
  275. \index{plot}
  276. In general the interaction between REDUCE and GNUPLOT is performed
  277. as silently as possible. However, sometimes it might be useful
  278. to see the GNUPLOT commands generated by REDUCE, e.g. for a
  279. postprocessing of generated data sets independent of REDUCE.
  280. When the switch \name{trplot} is set on all GNUPLOT commands will
  281. be printed to the standard output additionally.
  282. \end{Switch}