Functions and Variables for Plotting
====================================

 -- Function: contour_plot (EXPR, X_RANGE, Y_RANGE, OPTIONS, ...)

     Plots the contours (curves of equal value) of EXPR over the region X_RANGE by Y_RANGE. Any additional arguments are treated the same as in plot3d.

     contour_plot only works when the plot format is gnuplot or gnuplot_pipes.

     See also implicit_plot.

     Examples:

          (%i1) contour_plot (x^2 + y^2, [x, -4, 4], [y, -4, 4]);
          (%o1)
          (%i2) contour_plot (sin(y) * cos(x)^2, [x, -4, 4], [y, -4, 4]);
          (%o2)
          (%i3) F(x, y) := x^3 + y^2;
                                             3    2
          (%o3)                  F(x, y) := x  + y
          (%i4) contour_plot (F, [u, -4, 4], [v, -4, 4]);
          (%o4)
          (%i5) contour_plot (F, [u, -4, 4], [v, -4, 4], [gnuplot_preamble,
                "set size ratio -1"]);
          (%o5)
          (%i6) set_plot_option ([gnuplot_preamble,
                                  "set cntrparam levels 12"])$

          (%i7) contour_plot (F, [u, -4, 4], [v, -4, 4]);

 -- Option variable: in_netmath
     Default value: false

     When in_netmath is true, plot3d prints OpenMath output to the console if plot_format is openmath; otherwise in_netmath (even if true) has no effect. in_netmath has no effect on plot2d.

 -- Function: plot2d (EXPR, X_RANGE, ..., OPTIONS, ...)
 -- Function: plot2d ([EXPR_1, ..., EXPR_N], ..., OPTIONS, ...)
 -- Function: plot2d ([EXPR_1, ..., EXPR_N], X_RANGE,..., OPTIONS, ...)

     Where EXPR, EXPR_1, ..., EXPR_N can be either expressions, or Maxima or Lisp functions or operators, or a list with the any of the forms: [discrete, [X1, ..., XN], [Y1, ..., YN]], [discrete, [[X1, Y1], ..., [XN, ..., YN]] or [parametric, X_EXPR, Y_EXPR, T_RANGE].

     Displays a plot of one or more expressions as a function of one variable.

     plot2d plots one expression EXPR or several expressions [NAME_1, ..., NAME_N]. The expressions that are not of the parametic or discrete types should all depend only on one variable VAR and it will be mandatory the use of X_RANGE to name that variable and gives its minimum and maximum values, using the syntax: [VARIABLE, MIN, MAX]. The plot will show the horizontal axis bound by the values of MIN and MAX.

     A expression to be plotted can also be given in the discrete or parametric forms. Namely, as a list starting with the word ``discrete'' or ``parametric''. The keyword DISCRETE must be followed by two lists of values, both with the same length, which are the horizontal and vertical coordinates of a set of points; alternatively, the coordinates of each point can be put into a list with two values, and all the coordinates of the points should be inside another list. The keyword PARAMETRIC must be followed by two expressions X_EXPR and Y_EXPR, and a range of the form [PARAM, MIN, MAX]. The two expressions must depend only on the parameter PARAM, and the plot will show the path traced out by the point with coordinates (X_EXPR, Y_EXPR) as PARAM increases from MIN to MAX.

     The range of the vertical axis is not mandatory. It is one more of the options for the command, with the syntax: [y, MIN, MAX]. If that option is used, the plot will show that entire range, even if the expressions do not reach all that range. Otherwise, if a vertical range is not specified by set_plot_option, the boundaries of the vertical axis will be set up automatically.

     All other options should also be lists, starting with the name of the option. The option XLABEL can be used to give a label for the horizontal axis; if that option is not used, the horizontal axis will be labeled with the name of the variable specified in X_RANGE, or with the expression X_EXPR in the case of just one parametric expression, or it will be left blank otherwise.

     A label for the vertical axis can be given with the YLABEL option. If there is only one expression to be plotted and the YLABEL option was not used, the vertical axis will be labeled with that expression, unless it is too large, or with the expression Y_EXPR if the expression is parametric, or with the text ``discrete data'' if the expression is discrete.

     The options [logx] and [logy] do not need any parameters. They will make the horizontal and vertical axes be scaled logarithmically.

     If there are several expressions to be plotted, a legend will be written to identiy each of the expressions. The labels that should be used in that legend can be given with the option LEGEND. If that option is not used, Maxima will create labels from the expressions.

     By default, the expressions are plotted as a set of line segments joining adjacent points within a set of points which is either given in the DISCRETE form, or calculated automatically from the expression given, using an algorithm that automatically adapts the steps among points using as an initial estimate of the total number of points the value set with the NTICKS option. The option STYLE can be used to make one of the expressions to be represented as a set of isolated points, or as points and line segments.

     There are several global options stored in the list PLOT_OPTIONS which can be modified with the function set_plot_option; any of those global options can be overriden with options given in the PLOT2D command.

     A function to be plotted may be specified as the name of a Maxima or Lisp function or operator, a Maxima lambda expression, or a general Maxima expression.  If specified as a name or a lambda expression, the function must be a function of one argument.

     Examples:

     Plots of common functions.

          (%i1) plot2d (sin(x), [x, -5, 5])$

          (%i2) plot2d (sec(x), [x, -2, 2], [y, -20, 20], [nticks, 200])$

     Plotting functions by name.

          (%i3) F(x) := x^2 $

          (%i4) :lisp (defun |$g| (x) (m* x x x))

          $g
          (%i5) H(x) := if x < 0 then x^4 - 1 else 1 - x^5 $

          (%i6) plot2d (F, [u, -1, 1])$

          (%i7) plot2d ([F, G, H], [u, -1, 1], [y, -1.5, 1.5])$

     We can plot a circle using a parametric plot with a parameter T. It is not necessary to give a range for the horizontal range, since the range of the parameter T determines the domain. However, since the graph's horizontal and vertical axes lengths are in the 4 to 3 proportion, we will use the XRANGE option to obtain the same scaling in both axes:

          (%i8) plot2d ([parametric, cos(t), sin(t), [t,-%pi,%pi],
                [nticks,80]], [x, -4/3, 4/3])$

     If we repeat that plot with only 8 points and extending the range of the parameter to give two turns, we will obtain the plot of a star:

          (%i9) plot2d ([parametric, cos(t), sin(t), [t, -%pi*2, %pi*2],
                  [nticks, 8]], [x, -2, 2], [y, -1.5, 1.5])$

     Combination of an ordinary plot of a cubic polynomial with a parametric plot of a circle:

          (%i10) plot2d ([x^3+2, [parametric, cos(t), sin(t), [t, -5, 5],
                  [nticks, 80]]], [x, -3, 3])$

     Example of a logarithmic plot:

          (%i11) plot2d (exp(3*s), [s, -2, 2], [logy])$

     To show some examples of discrete plots, we will start by entering the coordinates of 5 points, in the two different ways that can be used:

          (%i12) xx:[10, 20, 30, 40, 50]$
          (%i13) yy:[.6, .9, 1.1, 1.3, 1.4]$
          (%i14) xy:[[10,.6], [20,.9], [30,1.1], [40,1.3], [50,1.4]]$

     To plot those data points, joined with line segments, we use:

          (%i15) plot2d([discrete,xx,yy])$

     We will now show the plot with only points, and illustrating the use of the second way of giving the points coordinates:

          (%i16) plot2d([discrete, xy], [style, points])$

     The plot of the data points can be shown together with a plot of the theoretical function that predicts the data:

          (%i17) plot2d([[discrete,xy], 2*%pi*sqrt(l/980)], [l,0,50],
                  [style, [points,3,5], [lines,1,3]],
                  [legend,"experiment","theory"],
                  [xlabel,"pendulum's length (cm)"], [ylabel,"period (s)"])$

     See also plot_options, which describes plotting options and has more examples.

 -- Function: xgraph_curves (LIST)
     graphs the list of `point sets' given in list by using xgraph. If the program xgraph is not installed, this command will fail.

     A point set may be of the form

          [x0, y0, x1, y1, x2, y2, ...]

     or

          [[x0, y0], [x1, y1], ...]

     A point set may also contain symbols which give labels or other information.

          xgraph_curves ([pt_set1, pt_set2, pt_set3]);

     graph the three point sets as three curves.

          pt_set: append (["NoLines: True", "LargePixels: true"],
                                    [x0, y0, x1, y1, ...]);

     would make the point set (and subsequent ones), have no lines between points, and to use large pixels. See the man page on xgraph for more options to specify.

          pt_set: append ([concat ("\"", "x^2+y")], [x0, y0, x1, y1, ...]);

     would make there be a "label" of "x^2+y" for this particular point set.    The " at the beginning is what tells xgraph this is a label.

          pt_set: append ([concat ("TitleText: Sample Data")], [x0, ...])$

     would make the main title of the plot be "Sample Data" instead of "Maxima Plot".

     To make a bar graph with bars which are 0.2 units wide, and to plot two possibly different such bar graphs:

          (%i1) xgraph_curves ([append (["BarGraph: true", "NoLines: true",
                "BarWidth: .2"], create_list ([i - .2, i^2], i, 1, 3)),
                append (["BarGraph: true", "NoLines: true", "BarWidth: .2"],
                create_list ([i + .2, .7*i^2], i, 1, 3))]);

     A temporary file xgraph-out is used.

 -- System variable: plot_options
     Elements of this list state the default options for plotting. If an option is present in a plot2d or plot3d call, that value takes precedence over the default option. Otherwise, the value in plot_options is used. Default options are assigned by set_plot_option.

     Each element of plot_options is a list of two or more items. The first item is the name of an option, and the remainder comprises the value or values assigned to the option. In some cases the, the assigned value is a list, which may comprise several items.

     The plot options which are recognized by plot2d and plot3d are the following:

       * Option: plot_format

          Determines which graphic interface is used by plot2d and plot3d.

            * Value: gnuplot default on Windows

               Gnuplot is the most advanced plotting package among the packages available in Maxima. It requires an external gnuplot installation.

            * Value: gnuplot_pipes default on non-Windows platforms

               Similar to the gnuplot format except that communication with gnuplot is done through a pipe. It should be used to plot on screen, for plotting to files it is better to use the gnuplot format.

            * Value: mgnuplot

               Mgnuplot is a Tk-based wrapper around gnuplot. It is included in the Maxima distribution. Mgnuplot offers a rudimentary GUI for gnuplot, but has fewer overall features than the plain gnuplot interface. Mgnuplot requires an external gnuplot installation and Tcl/Tk.

            * Value: openmath

               Openmath is a Tcl/Tk GUI plotting program. This format is provided by Xmaxima, which is distributed together with Maxima; in order to use this format you should install the package Xmaxima, and it will work not only from Xmaxima itself, but also from the command line and other GUI's for Maxima.

       * Option: run_viewer

          Controls whether or not the appropriate viewer for the plot format should be run.

            * Default value: true

               Execute the viewer program.

            * Value: false

               Do not execute the viewer program.

       * Option: y

          The vertical range of the plot.

          Example:

               [y, - 3, 3]

          Sets the vertical range to [-3, 3].

       * Option: plot_realpart

          When plot_realpart is true, the real part of a complex value X is plotted; this is equivalent to plotting realpart(X) instead of X. Otherwise, only values with imaginary part equal to 0 are plotted, and complex values are ignored.

          Example:

               plot2d (log(x), [x, -5, 5], [plot_realpart, false]);
               plot2d (log(x), [x, -5, 5], [plot_realpart, true]);

          The default value is false.

       * Option: nticks

          In plot2d, it is gives the initial number of points used by the adaptive plotting routine for plotting functions. It is also the number of points that will be shown in a parametric plot.

          Example:

               [nticks, 20]

          The default for nticks is 10.

       * Option: adapt_depth

          The maximum number of splittings used by the adaptive plotting routine.

          Example:

               [adapt_depth, 5]

          The default for adapt_depth is 10.

       * Option: xlabel

          The label for the horizontal axis in a 2d plot.

          Example:

               [xlabel, "Time in seconds"]

       * Option: ylabel

          The label of the vertical axis in a 2d plot.

          Example:

               [ylabel, "Temperature"]

       * Option: logx

          It makes the horizontal axis of a 2d plot to be rendered in a logarithmic scale. It does not need any aditional parameters.

       * Option: logy

          It makes the vertical axis of a 2d plot to be rendered in a logarithmic scale. It does not need any aditional parameters.

       * Option: legend

          The labels for the various expressions in a 2d plot with several expressions. If there are more expressions than the number of labels given, they will be repeated. By default, the names of the expressions or functions will be used, or the words discrete1, discrete2, ..., for discrete sets of points.

          Example:

               [legend, "Set 1", "Set 2", "Set 3"]

       * Option: style

          The styles that will be used for the various functions or sets of data in a 2d plot. The word STYLE must be followed by one or more styles. If there are more functions and data sets than the styles given, the styles will be repeated. Each style can be either LINES for line segments, POINTS for isolated points, LINESPOINTS for segments and points, or DOTS for small isolated dots. Gnuplot accepts also an IMPULSES style.

          Each of the styles can be enclosed inside a list with some aditional parameters. LINES accepts one or two numbers: the width of the line and an integer that identifies a color. POINTS accepts one or two parameters; the first parameter is the radius of the points and the second parameter is an integer that in Gnuplot selects different shapes and colors for the points and in Openmath changes the color used for the points. LINESDOTS accepts up to four parameters; the first two are the same as for LINES and the last two are the same as for POINTS.

          Example:

               [style,[lines,2,3],[points,1,4]]

          In Gnuplot, this will plot the first (and third, fifth, etc) expression with blue line segments of width 2, and the second (and fourth, sixth, etc) expression with green squares of size 1. In Openmath, the first expression will be plotted with magenta lines of width 2, and the second with orange points of radius 1; notice that openmath_color(3) and openmath_color(4) return ``magenta'' and ``orange''.

          The default for the style option is LINES with a width of 1, and different colors.

       * Option: grid

          Sets the number of grid points to use in the x- and y-directions for three-dimensional plotting.

          Example:

               [grid, 50, 50]

          sets the grid to 50 by 50 points. The default grid is 30 by 30.

       * Option: transform_xy

          Allows transformations to be applied to three-dimensional plots.

          Example:

               [transform_xy, false]

          The default transform_xy is false. If it is not false, it should be the output of

               make_transform([x,y,z], f1(x,y,z), f2(x,y,z), f3(x,y,z))$

          The polar_xy transformation is built in. It gives the same transformation as

               make_transform ([r, th, z], r*cos(th), r*sin(th), z)$

     Gnuplot options:

     There are several plot options specific to gnuplot.  Some of these options are raw gnuplot commands, specified as strings. Refer to the gnuplot documentation for more details.

       * Option: gnuplot_term

          Sets the output terminal type for gnuplot.

            * Default value: default

               Gnuplot output is displayed in a separate graphical window.

            * Value: dumb

               Gnuplot output is displayed in the Maxima console by an "ASCII art" approximation to graphics.

            * Value: ps

               Gnuplot generates commands in the PostScript page description language. If the option gnuplot_out_file is set to FILENAME, gnuplot writes the PostScript commands to FILENAME. Otherwise, it is saved as maxplot.ps file.

            * Value: any other valid gnuplot term specification

               Gnuplot can generate output in many other graphical formats such as png, jpeg, svg etc.  To create plot in all these formats the gnuplot_term can be set to any supported gnuplot term name (symbol) or even full gnuplot term specification with any valid options (string). For example [gnuplot_term,png] creates output in PNG (Portable Network Graphics) format while [gnuplot_term,"png size 1000,1000"] creates PNG of 1000x1000 pixels size. If the option gnuplot_out_file is set to FILENAME, gnuplot writes the output to FILENAME. Otherwise, it is saved as maxplot.TERM file, where TERM is gnuplot terminal name.

       * Option: gnuplot_out_file

          Write gnuplot output to a file.

            * Default value: false

               No output file specified.

            * Value: FILENAME

               Example: [gnuplot_out_file, "myplot.ps"] This example sends PostScript output to the file myplot.ps when used in conjunction with the PostScript gnuplot terminal.

       * Option: gnuplot_pm3d

          Controls the usage PM3D mode, which has advanced 3D features. PM3D is only available in gnuplot versions after 3.7. The default value for gnuplot_pm3d is false.

          Example:

               [gnuplot_pm3d, true]

       * Option: gnuplot_preamble

          Inserts gnuplot commands before the plot is drawn. Any valid gnuplot commands may be used. Multiple commands should be separated with a semi-colon. The example shown produces a log scale plot. The default value for gnuplot_preamble is the empty string "".

          Example:

               [gnuplot_preamble, "set log y"]

       * Option: gnuplot_curve_titles

          Controls the titles given in the plot key. The default value is [default], which automatically sets the title of each curve to the function plotted. If not [default], gnuplot_curve_titles should contain a list of strings, each of which is "title 'TITLE_STRING'". (To disable the plot key, add "set nokey" to gnuplot_preamble.)

          Example:

               [gnuplot_curve_titles,
               ["title 'My first function'", "title 'My second function'"]]

       * Option: gnuplot_curve_styles

          A list of strings controlling the appearance of curves, i.e., color, width, dashing, etc., to be sent to the gnuplot plot command. The default value is ["with lines 3", "with lines 1", "with lines 2", "with lines 5", "with lines 4", "with lines 6", "with lines 7"], which cycles through different colors. See the gnuplot documentation for plot for more information.

          Example:

               [gnuplot_curve_styles, ["with lines 7", "with lines 2"]]

       * Option: gnuplot_default_term_command

          The gnuplot command to set the terminal type for the default terminal. The default value is set term windows "Verdana" 15 in Windows systems, and set term x11 font "Helvetica,16" in X11 windows systems.

          Example:

               [gnuplot_default_term_command, "set term x11"]

       * Option: gnuplot_dumb_term_command

          The gnuplot command to set the terminal type for the dumb terminal. The default value is "set term dumb 79 22", which makes the text output 79 characters by 22 characters.

          Example:

               [gnuplot_dumb_term_command, "set term dumb 132 50"]

       * Option: gnuplot_ps_term_command

          The gnuplot command to set the terminal type for the PostScript terminal. The default value is "set size 1.5, 1.5;set term postscript eps enhanced color solid 24", which sets the size to 1.5 times gnuplot's default, and the font size to 24, among other things. See the gnuplot documentation for set term postscript for more information.

          Example:

          All the figures in the examples for the PLOT2D function in this manual were obtained from Postscript files that were generated after setting gnuplot_ps_term_command as:

               [gnuplot_ps_term_command, "set size 1.3, 1.3; \
                       set term postscript eps color solid lw 2.5 30"]

     Examples:

       * Saves a plot of sin(x) to the file sin.eps.

          (%i1) plot2d (sin(x), [x, 0, 2*%pi], [gnuplot_term, ps],
                                  [gnuplot_out_file, "sin.eps"])$

       * Uses the y option to chop off singularities and the gnuplot_preamble option to put the key at the bottom of the plot instead of the top.

          (%i2) plot2d ([gamma(x), 1/gamma(x)], [x, -4.5, 5], [y, -10, 10],
                               [gnuplot_preamble, "set key bottom"])$

       * Uses a very complicated gnuplot_preamble to produce fancy x-axis labels. (Note that the gnuplot_preamble string must be entered without any line breaks.)

          (%i3) my_preamble: "set xzeroaxis; set xtics ('-2pi' -6.283, \
          '-3pi/2' -4.712, '-pi' -3.1415, '-pi/2' -1.5708, '0' 0, \
          'pi/2' 1.5708, 'pi' 3.1415,'3pi/2' 4.712, '2pi' 6.283)"$

          (%i4) plot2d([cos(x), sin(x), tan(x), cot(x)],
                 [x, -2*%pi, 2.1*%pi], [y, -2, 2],
                 [gnuplot_preamble, my_preamble]);

       * Uses a very complicated gnuplot_preamble to produce fancy x-axis labels, and produces PostScript output that takes advantage of the advanced text formatting available in gnuplot. (Note that the gnuplot_preamble string must be entered without any line breaks.)

          (%i5) my_preamble: "set xzeroaxis; set xtics ('-2{/Symbol p}' \
          -6.283, '-3{/Symbol p}/2' -4.712, '-{/Symbol p}' -3.1415, \
          '-{/Symbol p}/2' -1.5708, '0' 0,'{/Symbol p}/2' 1.5708, \
          '{/Symbol p}' 3.1415,'3{/Symbol p}/2' 4.712, '2{/Symbol p}' \
          6.283)"$

          (%i6) plot2d ([cos(x), sin(x), tan(x)], [x, -2*%pi, 2*%pi],
              [y, -2, 2], [gnuplot_preamble, my_preamble],
              [gnuplot_term, ps], [gnuplot_out_file, "trig.eps"]);

       * A three-dimensional plot using the gnuplot pm3d terminal.

          (%i7) plot3d (atan (-x^2 + y^3/4), [x, -4, 4], [y, -4, 4],
                  [grid, 50, 50], [gnuplot_pm3d, true])$

       * A three-dimensional plot without a mesh and with contours projected on the bottom plane.

          (%i8) my_preamble: "set pm3d at s;unset surface;set contour;\
          set cntrparam levels 20;unset key"$
          (%i9) plot3d(atan(-x^2 + y^3/4), [x, -4, 4], [y, -4, 4],
              [grid, 50, 50], [gnuplot_pm3d, true],
              [gnuplot_preamble, my_preamble])$

       * A plot where the z-axis is represented by color only. (Note that the gnuplot_preamble string must be entered without any line breaks.)

          (%i10) plot3d (cos (-x^2 + y^3/4), [x, -4, 4], [y, -4, 4],
              [gnuplot_preamble, "set view map; unset surface"],
              [gnuplot_pm3d, true], [grid, 150, 150])$

 -- Function: plot3d ([EXPR_1, EXPR_2, EXPR_3], X_RANGE, Y_RANGE, ..., OPTIONS, ...)
 -- Function: plot3d (EXPR, X_RANGE, Y_RANGE, ..., OPTIONS, ...)
 -- Function: plot3d (NAME, X_RANGE, Y_RANGE, ..., OPTIONS, ...)
 -- Function: plot3d ([EXPR_1, EXPR_2, EXPR_3], X_RGE, Y_RGE)
 -- Function: plot3d ([NAME_1, NAME_2, NAME_3], X_RANGE, Y_RANGE, ..., OPTIONS, ...)

     Displays a plot of one or three expressions as functions of two variables.

          (%i1) plot3d (2^(-u^2 + v^2), [u, -3, 3], [v, -2, 2]);

     plots z = 2^(-u^2+v^2) with u and v varying in [-3,3] and [-2,2] respectively, and with U on the x axis, and v on the y axis.

     The same graph can be plotted using openmath (if Xmaxima is installed):

          (%i2)  plot3d (2^(-u^2 + v^2), [u, -3, 3], [v, -2, 2],
                         [plot_format, openmath]);

     in this case the mouse can be used to rotate the plot to look at the surface from different sides.

     An example of the third pattern of arguments is

          (%i3) plot3d ([cos(x)*(3 + y*cos(x/2)), sin(x)*(3 + y*cos(x/2)),
             y*sin(x/2)], [x, -%pi, %pi], [y, -1, 1], ['grid, 50, 15]);

     which plots a Moebius band, parametrized by the three expressions given as the first argument to plot3d.  An additional optional argument ['grid, 50, 15] gives the grid number of rectangles in the x direction and y direction.

     The function to be plotted may be specified as the name of a Maxima or Lisp function or operator, a Maxima lambda expression, or a general Maxima expression. In the form plot3d (F, ...) where F is the name of a function or a lambda expression, the function must be a function of two arguments. In the form plot3d ([F_1, F_2, F_3], ...) where F_1, F_2, and F_3 are names of functions or lambda expressions, each function must be a function of three arguments.

     This example shows a plot of the real part of z^1/3.

          (%i4) plot3d (r^.33*cos(th/3), [r, 0, 1], [th, 0, 6*%pi],
                ['grid, 12, 80], ['transform_xy, polar_to_xy]);

     Other examples are the Klein bottle:

          (%i5) expr_1: 5*cos(x)*(cos(x/2)*cos(y) + sin(x/2)*sin(2*y)
                + 3.0) - 10.0$
          (%i6) expr_2: -5*sin(x)*(cos(x/2)*cos(y) + sin(x/2)*sin(2*y)
                + 3.0)$
          (%i7) expr_3: 5*(-sin(x/2)*cos(y) + cos(x/2)*sin(2*y))$

          (%i8) plot3d ([expr_1, expr_2, expr_3], [x, -%pi, %pi],
                [y, -%pi, %pi], ['grid, 40, 40]);

     and a torus:

          (%i9) expr_1: cos(y)*(10.0+6*cos(x))$
          (%i10) expr_2: sin(y)*(10.0+6*cos(x))$
          (%i11) expr_3: -6*sin(x)$
          (%i12) plot3d ([expr_1, expr_2, expr_3], [x, 0, 2*%pi],
                 [y, 0, 2*%pi], ['grid, 40, 40]);

     Sometimes it is necessary to define a function to plot the expression. All the arguments to plot3d are evaluated before being passed to plot3d, and so trying to make an expression which does just what is needed may be difficult, and it is just easier to make a function.

          (%i13) M: matrix([1, 2, 3, 4], [1, 2, 3, 2], [1, 2, 3, 4],
                 [1, 2, 3, 3])$
          (%i14) f(x, y) := float (M [?round(x), ?round(y)])$
          (%i15) plot3d (f, [x, 1, 4], [y, 1, 4], ['grid, 4, 4])$

     See plot_options for more examples.

 -- Function: make_transform (VARS, FX, FY, FZ)
     Returns a function suitable for the transform function in plot3d. Use with the plot option transform_xy.

          make_transform ([r, th, z], r*cos(th), r*sin(th), z)$

     is a transformation to polar coordinates.

 -- Function: set_plot_option (OPTION)
     Assigns one of the global variables for plotting. OPTION is specified as a list of two or more elements, in which the first element is one of the keywords on the plot_options list.

     set_plot_option evaluates its argument and returns the complete list plot_options (after modifying one of its elements).

     See also plot_options, plot2d, and plot3d.

     Examples:

     Modify the grid and x values. When a plot_options keyword has an assigned value, quote it to prevent evaluation.

          (%i1) set_plot_option ([grid, 30, 40]);
          (%o1) [[x, - 1.755559702014E+305, 1.755559702014E+305],
          [y, - 1.755559702014E+305, 1.755559702014E+305], [t, - 3, 3],
          [grid, 30, 40], [transform_xy, false], [run_viewer, true],
          [plot_format, gnuplot], [gnuplot_term, default],
          [gnuplot_out_file, false], [nticks, 10], [adapt_depth, 10],
          [gnuplot_pm3d, false], [gnuplot_preamble, ],
          [gnuplot_curve_titles, [default]],
          [gnuplot_curve_styles, [with lines 3, with lines 1,
          with lines 2, with lines 5, with lines 4, with lines 6,
          with lines 7]], [gnuplot_default_term_command, ],
          [gnuplot_dumb_term_command, set term dumb 79 22],
          [gnuplot_ps_term_command, set size 1.5, 1.5;set term postscript #
          eps enhanced color solid 24]]
          (%i2) x: 42;
          (%o2)                          42
          (%i3) set_plot_option (['x, -100, 100]);
          (%o3) [[x, - 100.0, 100.0], [y, - 1.755559702014E+305,
          1.755559702014E+305], [t, - 3, 3], [grid, 30, 40],
          [transform_xy, false], [run_viewer, true],
          [plot_format, gnuplot], [gnuplot_term, default],
          [gnuplot_out_file, false], [nticks, 10], [adapt_depth, 10],
          [gnuplot_pm3d, false], [gnuplot_preamble, ],
          [gnuplot_curve_titles, [default]],
          [gnuplot_curve_styles, [with lines 3, with lines 1,
          with lines 2, with lines 5, with lines 4, with lines 6,
          with lines 7]], [gnuplot_default_term_command, ],
          [gnuplot_dumb_term_command, set term dumb 79 22],
          [gnuplot_ps_term_command, set size 1.5, 1.5;set term postscript #
          eps enhanced color solid 24]]

Functions for working with the gnuplot_pipes format
---------------------------------------------------

 -- Function: gnuplot_start ()

     Opens the pipe to gnuplot used for plotting with the gnuplot_pipes format. Is not necessary to manually open the pipe before plotting.

 -- Function: gnuplot_close ()

     Closes the pipe to gnuplot which is used with the gnuplot_pipes format.

 -- Function: gnuplot_restart ()

     Closes the pipe to gnuplot which is used with the gnuplot_pipes format and opens a new pipe.

 -- Function: gnuplot_replot ()
 -- Function: gnuplot_replot (S)

     Updates the gnuplot window. If gnuplot_replot is called with a gnuplot command in a string S, then s is sent to gnuplot before reploting the window.

 -- Function: gnuplot_reset ()

     Resets the state of gnuplot used with the gnuplot_pipes format. To update the gnuplot window call gnuplot_replot after gnuplot_reset.