(maxima.info)Functions and Variables for Plotting


Next: Plotting Options Prev: Plotting Formats Up: Plotting
Enter node , (file) or (file)node

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

 -- Function: contour_plot (<expr>, <x_range>, <y_range>, <options>,
          ...)

     It 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'.

     This function only works when the plot format is either 'gnuplot'
     or 'gnuplot_pipes'.  The additional package 'implicit_plot', which
     works in any graphic format, can also be used to plot contours but
     a separate expression must be given for each contour.

     Examples:

          (%i1) contour_plot (x^2 + y^2, [x, -4, 4], [y, -4, 4])$

     You can add any options accepted by 'plot3d'; for instance, the
     option 'legend' with a value of false, to remove the legend.  By
     default, Gnuplot chooses and displays 3 contours.  To increase the
     number of contours, it is necessary to use a custom
     'gnuplot_preamble', as in the next example:

          (%i1) contour_plot (u^3 + v^2, [u, -4, 4], [v, -4, 4],
                        [legend,false],
                        [gnuplot_preamble, "set cntrparam levels 12"])$

 -- System variable: geomview_command

     This variable stores the name of the command used to run the
     geomview program when the plot format is 'geomview'.  Its default
     value is "geomview".  If the geomview program is not found unless
     you give its complete path or if you want to try a different
     version of it, you may change the value of this variable.  For
     instance,

          (%i1) geomview_command: "/usr/local/bin/my_geomview"$

 -- Function: get_plot_option (<keyword>, <index>)

     Returns the current default value of the option named <keyword>,
     which is a list.  The optional argument <index> must be a positive
     integer which can be used to extract only one element from the list
     (element 1 is the name of the option).

     See also 'set_plot_option', 'remove_plot_option' and the section on
     Plotting Options.

 -- System variable: gnuplot_command

     This variable stores the name of the command used to run the
     gnuplot program when the plot format is 'gnuplot'.  Its default
     value is "gnuplot".  If the gnuplot program is not found unless you
     give its complete path or if you want to try a different version of
     it, you may change the value of this variable.  For instance,

          (%i1) gnuplot_command: "/usr/local/bin/my_gnuplot"$

 -- System variable: gnuplot_file_args

     When a graphic file is going to be created using 'gnuplot', this
     variable is used to specify the way the file name should be passed
     to gnuplot.  Its default value is "~s", which means that the name
     of the file will be passed directly.  The contents of this variable
     can be changed in order to add options for the gnuplot program,
     adding those options before the format directive "~s".

 -- System variable: gnuplot_view_args

     This variable is used to parse the argument that will be passed to
     the gnuplot program when the plot format is 'gnuplot'.  Its default
     value is "-persist ~s", where "~s" will be replaced with the name
     of the file where the gnuplot commands have been written (usually
     "maxout_xxx.gnuplot").  The option '-persist' tells gnuplot to exit
     after the commands in the file have been executed, without closing
     the window that displays the plot.

     Those familiar with gnuplot, might want to change the value of this
     variable.  For example, by changing it to:

          (%i1) gnuplot_view_args: "~s -"$

     gnuplot will not be closed after the commands in the file have been
     executed; thus, the window with the plot will remain, as well as
     the gnuplot interactive shell where other commands can be issued in
     order to modify the plot.

     In Windows versions of Gnuplot older than 4.6.3 the behavior of "~s
     -" and "-persist ~s" were the opposite; namely, "-persist ~s" made
     the plot window and the gnuplot interactive shell remain, while "~s
     -" closed the gnuplot shell keeping the plot window.  Therefore,
     when older gnuplot versions are used in Windows, it might be
     necessary to adjust the value of 'gnuplot_view_args'.

 -- Function: implicit_plot
          implicit_plot (<expr>, <x_range>, <y_range>)
          implicit_plot ([<expr_1>, ..., <expr_n>], <x_range>,
          <y_range>)

     Displays a plot of a function on the real plane, defined implicitly
     by the expression <expr>.  The domain in the plane is defined by
     <x_range> and <y_range>.  Several functions can be represented on
     the same plot, giving a list [<expr_1>, ..., <expr_n>] of
     expressions that define them.  This function uses the global format
     options set up with the 'set_plot_option'.  Additional options can
     also be given as extra arguments for the 'implicit_plot' command.

     The method used by 'implicit_plot' consists of tracking sign
     changes on the domain given and it can fail for complicated
     expressions.

     'load(implicit_plot)' loads this function.

     Example:
          (%i1) load(implicit_plot)$
          (%i2) implicit_plot (x^2 = y^3 - 3*y + 1, [x, -4, 4], [y, -4, 4])$

 -- Function: julia (<x>, <y>, ...<options>...)

     Creates a graphic representation of the Julia set for the complex
     number (<x> + i <y>).  The two mandatory parameters <x> and <y>
     must be real.  This program is part of the additional package
     'dynamics', but that package does not have to be loaded; the first
     time julia is used, it will be loaded automatically.

     Each pixel in the grid is given a color corresponding to the number
     of iterations it takes the sequence that starts at that point to
     move out of the convergence circle of radius 2 centered at the
     origin.  The number of pixels in the grid is controlled by the
     'grid' plot option (default 30 by 30).  The maximum number of
     iterations is set with the option 'iterations'.  The program uses
     its own default palette: magenta,violet, blue, cyan, green, yellow,
     orange, red, brown and black, but it can be changed by adding an
     explicit 'palette' option in the command.

     The default domain used goes from -2 to 2 in both axes and can be
     changed with the 'x' and 'y' options.  By default, the two axes are
     shown with the same scale, unless the option 'yx_ratio' is used or
     the option 'same_xy' is disabled.  Other general plot options are
     also accepted.

     The following example shows a region of the Julia set for the
     number -0.55 + i0.6.  The option 'color_bar_tics' is used to
     prevent Gnuplot from adjusting the color box up to 40, in which
     case the points corresponding the maximum 36 iterations would not
     be black.

          (%i1) julia (-0.55, 0.6, [iterations, 36], [x, -0.3, 0.2],
                [y, 0.3, 0.9], [grid, 400, 400], [color_bar_tics, 0, 6, 36])$

 -- Function: make_transform ([<var1>, <var2>, <var3>], <fx>, <fy>,
          <fz>)

     Returns a function suitable to be used in the option 'transform_xy'
     of plot3d.  The three variables <var1>, <var2>, <var3> are three
     dummy variable names, which represent the 3 variables given by the
     plot3d command (first the two independent variables and then the
     function that depends on those two variables).  The three functions
     <fx>, <fy>, <fz> must depend only on those 3 variables, and will
     give the corresponding x, y and z coordinates that should be
     plotted.  There are two transformations defined by default:
     'polar_to_xy' and 'spherical_to_xyz'.  See the documentation for
     those two transformations.

 -- Function: mandelbrot (<options>)

     Creates a graphic representation of the Mandelbrot set.  This
     program is part of the additional package 'dynamics', but that
     package does not have to be loaded; the first time mandelbrot is
     used, the package will be loaded automatically.

     This program can be called without any arguments, in which case it
     will use a default value of 9 iterations per point, a grid with
     dimensions set by the 'grid' plot option (default 30 by 30) and a
     region that extends from -2 to 2 in both axes.  The options are all
     the same that plot2d accepts, plus an option 'iterations' to change
     the number of iterations.

     Each pixel in the grid is given a color corresponding to the number
     of iterations it takes the sequence starting at zero to move out of
     the convergence circle of radius 2, centered at the origin.  The
     maximum number of iterations is set by the option 'iterations'.
     The program uses its own default palette: magenta,violet, blue,
     cyan, green, yellow, orange, red, brown and black, but it can be
     changed by adding an explicit 'palette' option in the command.  By
     default, the two axes are shown with the same scale, unless the
     option 'yx_ratio' is used or the option 'same_xy' is disabled.

     Example:

     [grid,400,400])$
          (%i1) mandelbrot ([iterations, 30], [x, -2, 1], [y, -1.2, 1.2],
                      [grid,400,400])$

 -- System function: polar_to_xy

     It can be given as value for the 'transform_xy' option of plot3d.
     Its effect will be to interpret the two independent variables in
     plot3d as the distance from the z axis and the azimuthal angle
     (polar coordinates), and transform them into x and y coordinates.

 -- Function: plot2d
          plot2d (<plot>, <x_range>, ..., <options>, ...)
          plot2d ([<plot_1>, ..., <plot_n>], ..., <options>, ...)
          plot2d ([<plot_1>, ..., <plot_n>], <x_range>, ..., <options>,
          ...)

     Where <plot>, <plot_1>, ..., <plot_n> can be either expressions,
     function names 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 or parameter.

     'plot2d' displays one or several plots in two dimensions.  When
     expressions or function name are used to define the plots, they
     should all depend on only one variable <var> and the use of
     <x_range> will be mandatory, to provide the name of the variable
     and its minimum and maximum values; the syntax for <x_range> is:
     '[<variable>, <min>, <max>]'.

     A plot can also be defined in the discrete or parametric forms.
     The discrete form is used to plot a set of points with given
     coordinates.  A discrete plot is defined by a list starting with
     the keyword <discrete>, followed by one or two lists of values.  If
     two lists are given, they must have the same length; the first list
     will be interpreted as the x coordinates of the points to be
     plotted and the second list as the y coordinates.  If only one list
     is given after the <discrete> keyword, each element on the list
     could also be a list with two values that correspond to the x and y
     coordinates of a point, or it could be a sequence of numerical
     values which will be plotted at consecutive integer values
     (1,2,3,...)  on the x axis.

     A parametric plot is defined by a list starting with the keyword
     <parametric>, followed by two expressions or function names and a
     range for the parameter.  The range for the parameter must be a
     list with the name of the parameter followed by its minimum and
     maximum values: '[<param>, <min>, <max>]'.  The plot will show the
     path traced out by the point with coordinates given by the two
     expressions or functions, as <param> increases from <min> to <max>.

     A range for the vertical axis is an optional argument with the
     form: '[y, <min>, <max>]' (the keyword <y> is always used for the
     vertical axis).  If that option is used, the plot will show that
     exact vertical range, independently of the values reached by the
     plot.  If the vertical range is not specified, it will be set up
     according to the minimum and maximum values of the second
     coordinate of the plot points.

     All other options should also be lists, starting with a keyword and
     followed by one or more values.  See 'plot_options'.

     If there are several plots to be plotted, a legend will be written
     to identity 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
     or function names.

     *Examples:*

     Plot of a common function:

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

     If the function grows too fast, it might be necessary to limit the
     values in the vertical axis using the 'y' option:

          (%i1) plot2d (sec(x), [x, -2, 2], [y, -20, 20])$

     When the plot box is disabled, no labels are created for the axes.
     In that case, instead of using 'xlabel' and 'ylabel' to set the
     names of the axes, it is better to use option 'label', which allows
     more flexibility.  Option 'yx_ratio' is used to change the default
     rectangular shape of the plot; in this example the plot will fill a
     square.

          (%i1) plot2d ( x^2 - 1, [x, -3, 3], [box, false], grid2d,
                [yx_ratio, 1], [axes, solid], [xtics, -2, 4, 2],
                [ytics, 2, 2, 6], [label, ["x", 2.9, -0.3],
                ["x^2-1", 0.1, 8]], [title, "A parabola"])$

     A plot with a logarithmic scale in the vertical axis:

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

     Plotting functions by name:

          (%i1) F(x) := x^2 $
          (%i2) :lisp (defun |$g| (x) (m* x x x))
          $g
          (%i2) H(x) := if x < 0 then x^4 - 1 else 1 - x^5 $
          (%i3) plot2d ([F, G, H], [u, -1, 1], [y, -1.5, 1.5])$

     A plot of the butterfly curve, defined parametrically:

          (%i1) r: (exp(cos(t))-2*cos(4*t)-sin(t/12)^5)$
          (%i2) plot2d([parametric, r*sin(t), r*cos(t), [t, -8*%pi, 8*%pi]])$

     Plot of a circle, using its parametric representation, together
     with the function -|x|.  The circle will only look like a circle if
     the scale in the two axes is the same, which is done with the
     option 'same_xy'.

          (%i1) plot2d([[parametric, cos(t), sin(t), [t,0,2*%pi]], -abs(x)],
                   [x, -sqrt(2), sqrt(2)], same_xy)$

     A plot of 200 random numbers between 0 and 9:

          (%i1) plot2d ([discrete, makelist ( random(10), 200)])$

     A plot of a discrete set of points, defining x and y coordinates
     separately:

          (%i1) plot2d ([discrete, makelist(i*%pi, i, 1, 5),
                                      [0.6, 0.9, 0.2, 1.3, 1]])$

     In the next example a table with three columns is saved in a file
     "data.txt" which is then read and the second and third column are
     plotted on the two axes:

          (%i1) with_stdout ("data.txt", for x:0 thru 10 do
                                       print (x, x^2, x^3))$
          (%i2) data: read_matrix ("data.txt")$
          (%i3) plot2d ([discrete, transpose(data)[2], transpose(data)[3]],
            [style,points], [point_type,diamond], [color,red])$

     A plot of discrete data points together with a continuous function:

          (%i1) xy: [[10, .6], [20, .9], [30, 1.1], [40, 1.3], [50, 1.4]]$
          (%i2) plot2d([[discrete, xy], 2*%pi*sqrt(l/980)], [l,0,50],
                  [style, points, lines], [color, red, blue],
                  [point_type, asterisk],
                  [legend, "experiment", "theory"],
                  [xlabel, "pendulum's length (cm)"],
                  [ylabel, "period (s)"])$

     See also the section about Plotting Options.

 -- Function: plot3d
          plot3d (<expr>, <x_range>, <y_range>, ..., <options>, ...)
          plot3d ([<expr_1>, ..., <expr_n>], <x_range>, <y_range>, ...,
          <options>, ...)

     Displays a plot of one or more surfaces defined as functions of two
     variables or in parametric form.

     The functions to be plotted may be specified as expressions or
     function names.  The mouse can be used to rotate the plot looking
     at the surface from different sides.

     *Examples:*

     Plot of a function of two variables:

          (%i1) plot3d (u^2 - v^2, [u, -2, 2], [v, -3, 3], [grid, 100, 100],
                  [mesh_lines_color,false])$

     Use of the 'z' option to limit a function that goes to infinity (in
     this case the function is minus infinity on the x and y axes); this
     also shows how to plot with only lines and no shading:

          (%i1) plot3d ( log ( x^2*y^2 ), [x, -2, 2], [y, -2, 2], [z, -8, 4],
                   [palette, false], [color, magenta])$

     The infinite values of z can also be avoided by choosing a grid
     that does not fall on any points where the function is undefined,
     as in the next example, which also shows how to change the palette
     and how to include a color bar that relates colors to values of the
     z variable:

          (%i1) plot3d (log (x^2*y^2), [x, -2, 2], [y, -2, 2],[grid, 29, 29],
                 [palette, [gradient, red, orange, yellow, green]],
                 color_bar, [xtics, 1], [ytics, 1], [ztics, 4],
                 [color_bar_tics, 4])$

     Two surfaces in the same plot.  Ranges specific to one of the
     surfaces can be given by placing each expression and its ranges in
     a separate list; global ranges for the complete plot are also given
     after the functions definitions.

          (%i1) plot3d ([[-3*x - y, [x, -2, 2], [y, -2, 2]],
             4*sin(3*(x^2 + y^2))/(x^2 + y^2), [x, -3, 3], [y, -3, 3]],
             [x, -4, 4], [y, -4, 4])$

     Plot of a Klein bottle, defined parametrically:

          (%i1) expr_1: 5*cos(x)*(cos(x/2)*cos(y)+sin(x/2)*sin(2*y)+3)-10$
          (%i2) expr_2: -5*sin(x)*(cos(x/2)*cos(y)+sin(x/2)*sin(2*y)+3)$
          (%i3) expr_3: 5*(-sin(x/2)*cos(y)+cos(x/2)*sin(2*y))$
          (%i4) plot3d ([expr_1, expr_2, expr_3], [x, -%pi, %pi],
                  [y, -%pi, %pi], [grid, 50, 50])$

     Plot of a "spherical harmonic" function, using the predefined
     transformation, 'spherical_to_xyz' to transform from spherical
     coordinates to rectangular coordinates.  See the documentation for
     'spherical_to_xyz'.

          (%i1) plot3d (sin(2*theta)*cos(phi), [theta, 0, %pi],
                  [phi, 0, 2*%pi],
                  [transform_xy, spherical_to_xyz], [grid,30,60],
             [legend,false])$

     Use of the pre-defined function 'polar_to_xy' to transform from
     cylindrical to rectangular coordinates.  See the documentation for
     'polar_to_xy'.

          (%i1) plot3d (r^.33*cos(th/3), [r,0,1], [th,0,6*%pi], [box, false],
             [grid, 12, 80], [transform_xy, polar_to_xy], [legend, false])$

     Plot of a sphere using the transformation from spherical to
     rectangular coordinates.  Option 'same_xyz' is used to get the
     three axes scaled in the same proportion.  When transformations are
     used, it is not convenient to eliminate the mesh lines, because
     Gnuplot will not show the surface correctly.

          (%i1) plot3d ( 5, [theta, 0, %pi], [phi, 0, 2*%pi], same_xyz,
            [transform_xy, spherical_to_xyz], [mesh_lines_color,blue],
            [palette,[gradient,"#1b1b4e", "#8c8cf8"]], [legend, false])$

     Definition of a function of two-variables using a matrix.  Notice
     the single quote in the definition of the function, to prevent
     'plot3d' from failing when it realizes that the matrix will require
     integer indices.

          (%i1) M: matrix([1,2,3,4], [1,2,3,2], [1,2,3,4], [1,2,3,3])$
          (%i2) f(x, y) := float('M [round(x), round(y)])$
          (%i3) plot3d (f(x,y), [x,1,4],[y,1,4],[grid,3,3],[legend,false])$

     By setting the elevation equal to zero, a surface can be seen as a
     map in which each color represents a different level.

          (%i1) plot3d (cos (-x^2 + y^3/4), [x,-4,4], [y,-4,4], [zlabel,""],
                 [mesh_lines_color,false], [elevation,0], [azimuth,0],
                 color_bar, [grid,80,80], [ztics,false], [color_bar_tics,1])$

     See also the section about Plotting Options.

 -- System variable: plot_options

     This option is being kept for compatibility with older versions,
     but its use is deprecated.  To set global plotting options, see
     their current values or remove options, use 'set_plot_option',
     'get_plot_option' and 'remove_plot_option'.

 -- Function: remove_plot_option (<name>)

     Removes the default value of an option.  The name of the option
     must be given.

     See also 'set_plot_option', 'get_plot_option' and the section on
     Plotting Options.

 -- Function: set_plot_option (<option>)

     Accepts any of the options listed in the section Plotting Options,
     and saves them for use in plotting commands.  The values of the
     options set in each plotting command will have precedence, but if
     those options are not given, the default values set with this
     function will be used.

     'set_plot_option' evaluates its argument and returns the complete
     list of options (after modifying the option given).  If called
     without any arguments, it will simply show the list of current
     default options.

     See also 'remove_plot_option', 'get_plot_option' and the section on
     Plotting Options.

     Example:

     Modification of the 'grid' values.

          (%i1) set_plot_option ([grid, 30, 40]);
          (%o1) [[plot_format, gnuplot_pipes], [grid, 30, 40],
          [run_viewer, true], [axes, true], [nticks, 29], [adapt_depth, 5],
          [color, blue, red, green, magenta, black, cyan],
          [point_type, bullet, box, triangle, plus, times, asterisk],
          [palette, [gradient, green, cyan, blue, violet],
          [gradient, magenta, violet, blue, cyan, green, yellow, orange,
          red, brown, black]], [gnuplot_preamble, ], [gnuplot_term, default]]

 -- System function: spherical_to_xyz

     It can be given as value for the 'transform_xy' option of 'plot3d'.
     Its effect will be to interpret the two independent variables and
     the function in 'plot3d' as the spherical coordinates of a point
     (first, the angle with the z axis, then the angle of the xy
     projection with the x axis and finally the distance from the
     origin) and transform them into x, y and z coordinates.


automatically generated by info2www version 1.2.2.9