gnuplot.tex 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. \documentstyle[11pt,reduce]{article}
  2. \date{}
  3. \title{GNUPLOT Interface for REDUCE\\Version 3}
  4. \author{Herbert Melenk \\
  5. Konrad--Zuse--Zentrum f\"ur Informationstechnik Berlin \\
  6. E--mail: Melenk@sc.zib--berlin.de}
  7. \begin{document}
  8. \maketitle
  9. \index{GNUPLOT package}
  10. \section{Introduction}
  11. The GUNPLOT system provides easy to use graphics output
  12. for curves or surfaces which are defined by
  13. formulas and/or data sets. GNUPLOT supports
  14. a great variety of output devices
  15. such as \verb+X-windows+, \verb+SUN tools+,
  16. \verb+VGA screen+, \verb+postscript+, \verb+pic+ \TeX.
  17. The {\small REDUCE} GNUPLOT package lets one use the GNUPLOT
  18. graphical output directly from inside {\small REDUCE}, either for
  19. the interactive display of curves/surfaces or for the production
  20. of pictures on paper.
  21. {\small REDUCE} supports GNUPLOT 3.2. For most systems GNUPLOT binaries
  22. are delivered together with {\small REDUCE}. However, this is a
  23. basic set only. If you intend to use more facilities of the GNUPLOT
  24. system or if your {\small REDUCE} has not been equipped with
  25. GNUPLOT binaries you should pick up the full GNUPLOT file tree
  26. from a server, e.g.
  27. \begin{itemize}
  28. \item dartmouth.edu (129.170.16.4)
  29. \item monu1.cc.monash.edu.au (130.194.1.101)
  30. \item irisa.irisa.fr (131.254.2.3)
  31. \end{itemize}
  32. Under UNIX {\small REDUCE} evaluates the environment variable
  33. $gnuplot$; if this variable has been set, {\small REDUCE} redirects
  34. the GNUPLOT calls to the directory described there. Otherwise the
  35. binaries are expected in the directory $\$reduce/plot$.
  36. \section{Incompatibilities}
  37. In contrast to the previous {\small REDUCE} GNUPLOT package
  38. this version computes all data points inside REDUCE and
  39. passes them to GNUPLOT as a data file.
  40. This simplifies the usage of the GNUPLOT package
  41. and reduces some incompatibilities and restrictions.
  42. \section{Loading GNUPLOT}
  43. If on your computer the {\small REDUCE} GNUPLOT package
  44. has been installed with autoload, you can call the command
  45. \verb+PLOT(...)+ directly from any {\small REDUCE} session;
  46. otherwise enter once per session
  47. \begin{verbatim}
  48. load_package gnuplot;
  49. \end{verbatim}
  50. \section{Command PLOT}
  51. The \verb+PLOT(...)+ command can have a variable number of
  52. parameters:
  53. \begin{itemize}
  54. \item A functions to plot; a function can be
  55. \begin{itemize}
  56. \item an expression with one unknown, e.g. $u*sin(u)**2$
  57. \item an expression with two unknowns, e.g.
  58. $u*sin(u)**2+sqrt(v)$
  59. \item an equation with a symbol on the left-hand side
  60. and an expression with one or two unknowns on the
  61. right-hand side, e.g.// $dome=1/(x**2+y**2)$
  62. \item a list of points in 2 or 3 dimensions
  63. e.g. \\ $\{0,0\},\{0,1\},\{1,1\}\}$ representing
  64. a curve,
  65. \item a list of lists of points in 2 or 3 dimensions
  66. e.g.\\ $\{\{0,0\},\{0,1\},\{1,1\}\}
  67. \{0,0\},\{0,1\},\{1,1\}\}\}$
  68. representing a family of curves.
  69. \end{itemize}
  70. \item A range for a variable; this has the form\\
  71. $variable=(lower\_bound\, . . \, upper\_bound)$ where
  72. $lower\_bound$ and $upper\_bound$ must be expressions which
  73. evaluate to numbers. If no range is specified the
  74. default ranges for independent variables are $(-10\,\,..\,\,10)$
  75. and the range for the dependent variable is set to
  76. maximum number of the GNUPLOT executable (using double
  77. floats on most IEEE machines and single floats under DOS).
  78. \item A GNUPLOT option, either as fixed keyword,
  79. e.g.\ $hidden3d$ or as equation e.g.\ $term=pictex$;
  80. free texts such as titles and labels such be enclosed in
  81. string quotes.
  82. \end{itemize}
  83. Please note that a blank has to be inserted between a number
  84. and a dot - otherwise the REDUCE translator will be mislead.
  85. If a function is given as an equation the left-hand side
  86. is mainly used as label for the axis of the dependent variable.
  87. In two dimensions more than one function expressions can be given
  88. which are drawns into one picture; however,
  89. all these have to use the same independent variable name.
  90. One of the functions can be a point set or a point set list.
  91. Normally all functions and point sets are plotted by
  92. lines; only if functions and point sets are drawn into
  93. one picture the point set is drawn by points.
  94. The functional expressions are evaluated in $rounded$ mode.
  95. This is done automatically - it is not necessary to turn
  96. on rounded mode explicitly.
  97. Examples:
  98. \begin{verbatim}
  99. plot(cos x);
  100. plot(s=sin phi,phi=(-3 .. 3));
  101. plot(sin phi,cos phi,phi=(-3 .. 3));
  102. plot (cos sqrt(x**2 + y**2),x=(-3 .. 3),y=(-3 .. 3),hidden3d);
  103. plot {{0,0},{0,1},{1,1},{0,0},{1,0},{0,1},{0.5,1.5},{1,1},{1,0}};
  104. % parametric: screw
  105. on rounded;
  106. w:=for j:=1:200 collect {1/j*sin j,1/j*cos j,j/200}$
  107. plot w;
  108. % parametric: globe
  109. dd:=pi/15$
  110. w:=for u:=dd step dd until pi-dd collect
  111. for v:=0 step dd until 2pi collect
  112. {sin(u)*cos(v), sin(u)*sin(v), cos(u)}$
  113. plot w;
  114. \end{verbatim}
  115. The following GNUPLOT options are supported:
  116. \begin{itemize}
  117. \item $title=name$: the title (string) is put on top
  118. of the picture.
  119. \item axes labels: $xlabel="text1"$, $ylabel="text2"$, and for
  120. surfaces $zlabel="text3"$. If omitted the axes are labeled
  121. by the independent and dependent variable names from the
  122. expression. Note that the axes names $x$label, $y$label and
  123. $z$label here are used in the usual sense, $x$ for the
  124. horizontal and $y$ for the vertical axis under 2-d and
  125. $z$ for the perpendicular axis under 3-d -- these names
  126. do not refer to the variable names used in the expressions.
  127. \begin{verbatim}
  128. plot(1,X,(4*X**2-1)/2,(X*(12*X**2-5))/3,
  129. x=(-1 .. 1), ylabel="L(x,n)",
  130. title="Legendre Polynomials");
  131. \end{verbatim}
  132. \item $terminal=name$: redirect output to device $name$.
  133. Every installation uses a default terminal as output
  134. device; some installations support additional
  135. devices such as printers; consult your local
  136. GNUPLOT installation material for details.
  137. If the GNUPLOT set terminal command allows
  138. additional parameters you have to form the full
  139. value set as string in {\small reduce};
  140. \item $size="s_x,s_y"$: rescale the graph (not the
  141. window) where $s_x$ and $s_y$ are scaling
  142. factors for the size in x or y
  143. direction. Defaults are $s_x=1,x_z=1$.
  144. Note that scaling factors greater than one
  145. often will cause the picture to be too big for
  146. the window.
  147. \begin{verbatim}
  148. plot(1/(x**2+y**2),x=(0.1 .. 5),
  149. y=(0.1 .. 5), size="0.7,1");
  150. \end{verbatim}
  151. \item $view="r_x,r_z"$: set viewpoint for 3 dimensions
  152. by turning the object around the x or z axis;
  153. the values are degrees (integers).
  154. Defaults are $r_x=60,r_z=30$.
  155. \begin{verbatim}
  156. plot(1/(x**2+y**2),x=(0.1 .. 5),
  157. y=(0.1 .. 5), view="30,130");
  158. \end{verbatim}
  159. \item $contour$ resp $nocontour$: in 3 dimensions an
  160. additional contour map is drawn (default: $nocontour$)
  161. \item $surface$ resp $nosurface$: in 3 dimensions the
  162. surface is drawn resp suppressed (default: $surface$).
  163. \item $hidden3d$: hidden line removal in 3 dimensions.
  164. \end{itemize}
  165. \section{Mesh generation}
  166. Per default the functions are computed at predefined
  167. mesh points: the ranges are divided by $plot\_xmesh$ resp
  168. $plot\_ymesh$, which are initially set to 20. These are
  169. share variables and you can modify them globally for your
  170. session by assigning different positive integer values.
  171. Note that these values cannot be set in the plot command directly and
  172. that the names $plot\_xmesh$ and $plot\_ymesh$ are
  173. builtin and have to be used even if the unknowns of your
  174. expressions have different names.
  175. For two dimensions the given mesh is adaptively
  176. smoothed when the curves are too coarse, especially
  177. if singularities are present. On the other hand
  178. refinement can be rather time consuming if used with
  179. complicated expressions. You can turn it off by
  180. $OFF$ $PLOTREFINE$. At singularities the graph is
  181. interrupted.
  182. In three dimensions no refinement is possible as surfaces
  183. can be drawn only with a fixed grid. In the case
  184. of a singularity the near neighbourhood is
  185. tested; if a point there allows a function evaluation, its
  186. clipped value used instead, otherwise a zero is inserted.
  187. When plotting surfaces in three dimensions you have the
  188. option of hidden line removal. Because of an error in
  189. Gnuplot 3.2 with "hidden3d" the axes cannot be labelled
  190. correctly; therefore they arn't labelled at all. Hidden line
  191. removal is not available with point lists.
  192. \section{GNUPLOT operation}
  193. The command verb+PLOTRESET;+ deletes the current GNUPLOT output
  194. window. The next call to verb+PLOT+ then will open a new one.
  195. If GNUPLOT is invoked directly by an output pipe (UNIX and Windows),
  196. an eventual error in the GNUPLOT data transmission might cause GNUPLOT to
  197. quit. As {\small REDUCE} is unable to detect the broken pipe, you
  198. have to reset the plot system by calling the
  199. command \verb+PLOTRESET;+ explicitly. Afterwards new graphic output
  200. can be produced.
  201. Under DOS Windows 3.1 GNUPLOT has a text and a graph window.
  202. If don't want to see the text window, iconify it and
  203. activate the option ``update wgnuplot.ini" from the
  204. graph window system menu - then the present screen layout
  205. (including the graph window size) will be saved and the text
  206. windows will com up iconified in future. You also can select
  207. some more features there and so tailor the gaphic output.
  208. Before you terminate {\small REDUCE} you should terminate the
  209. graphic window by calling verb+PLOTRESET;+.
  210. If you terminate {\small REDUCE} without deleting the
  211. GNUPLOT windows before, use the command button from the
  212. GNUPLOT text window - it offers an exit function.
  213. \section{Saving GNUPLOT command sequence}
  214. If you want to use the internal GNUPLOT command sequence
  215. more than once (e.g. for producing a picture for a publication),
  216. you best set
  217. $ON \,\, TRPLOT,PLOTKEEP$;
  218. $TRPLOT$ causes all GNUPLOT commands
  219. to be written additionally to the actual
  220. {\small REDUCE} output. Normally the data files are
  221. erased after calling GNUPLOT, however with $PLOTKEEP$ on
  222. the files are not erased.
  223. \section{Direct Call of GNUPLOT}
  224. GNUPLOT has many facilities which are not accessed by
  225. the operators and parameters described above. Therefore
  226. genuine GNUPLOT commands can be sent by {\small REDUCE}.
  227. Please consult the GNUPLOT manual for the available
  228. commands and parameters. The general syntax for a GNUPLOT call
  229. inside {\small REDUCE} is
  230. $gnuplot(<cmd>,<p_1>,<p_2> \cdots)$
  231. where $<cmd>$ is a command name and $<p_1>,<p_2> \cdots$
  232. are the parameters, inside {\small REDUCE} separated by
  233. commas. The parameters are evaluated by
  234. {\small REDUCE} and then transmitted to GNUPLOT in
  235. GNUPLOT syntax. Usually a drawing is built by a
  236. sequence of commands which are buffered
  237. by {\small REDUCE} or the operating
  238. system. For terminating and activating them use the {\small REDUCE}
  239. command $plotshow;$. Example:
  240. \begin{verbatim}
  241. gnuplot(set,polar);
  242. gnuplot(set,noparametric);
  243. gnuplot(plot,x*sin x);
  244. plotshow;
  245. \end{verbatim}
  246. Note that GNUPLOT restrictions with respect to variable
  247. and function names have to be taken into account when
  248. using this type of operation.
  249. \end{document}