Next: , Previous: , Up: Plotting   [Contents][Index]

12.3 Functions and Variables for Plotting

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"$
Categories: Plotting ·
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 or gnuplot_pipes. 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"$
Categories: Plotting ·
System variable: gnuplot_file_args

When a graphic file is going to be created using gnuplot, this variable is used to specify the format used to print the file name given to gnuplot. Its default value is "~a" in SBCL and Openmcl, and "~s" in other lisp versions, which means that the name of the file will be passed without quotes if SBCL or Openmcl are used and within quotes if other Lisp versions are used. 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".

Categories: Plotting ·
System variable: gnuplot_view_args

This variable is the format used to parse the argument that will be passed to the gnuplot program when the plot format is gnuplot. Its default value is "-persist ~a" when SBCL or Openmcl are used, and "-persist ~s" with other Lisp variants, where "~a" or "~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.

Categories: Plotting ·
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 sets 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])$
figures/plotting4
Categories: Package dynamics · Plotting ·
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.

Categories: Plotting ·
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])$
figures/plotting5
Categories: Package dynamics · Plotting ·
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.

Categories: Plotting ·
Function: plot2d
    plot2d (expr, range_x, options)
    plot2d (expr_1=expr_2, range_x, range_y, options)
    plot2d ([parametric, expr_x, expr_y, range], options)
    plot2d ([discrete, points], options)
    plot2d ([contour, expr], range_x, range_y, options)
    plot2d ([type_1, …, type_n], options)

There are 5 types of plots that can be plotted by plot2d:

  1. Explicit functions. plot2d (expr, range_x, options), where expr is an expression that depends on only one variable, or the name of a function with one input parameter and numerical results. range_x is a list with three elements, the first one being the name of the variable that will be shown on the horizontal axis of the plot, and the other two elements should be two numbers, the first one smaller than the second, that define the minimum and maximum values to be shown on the horizontal axis. The name of the variable used in range_x must be the same variable on which expr depends. The result will show in the vertical axis the corresponding values of the expression or function for each value of the variable in the horizontal axis.
  2. Implicit functions. plot2d (expr_1=expr_2, range_x, range_y, options), where expr_1 and expr_2 are two expressions that can depend on one or two variables. range_x and range_y must be two lists of three elements that define the ranges for the variables in the two axes of the plot; the first element of each list is the name of the corresponding variable, and the other two elements are the minimum and maximum values for that variable. The two variables on which expr_1 and expr_2 can depend are those specified by range_x and range_y. The result will be a curve or a set of curves where the equation expr_1=expr_2 is true.
  3. Parametric functions. plot2d ([parametric, expr_x, expr_y, range], options), where expr_x and expr_y are two expressions that depend on a single parameter. range must be a three-element list; the first element must be the name of the parameter on which expr_x and expr_y depend, and the other two elements must be the minimum and maximum values for that parameter. The result will be a curve in which the horizontal and vertical coordinates of each point are the values of expr_x and expr_y for a value of the parameter within the range given.
  4. Set of points. plot2d ([discrete, points], options), displays a list of points, joined by segments by default. The horizontal and vertical coordinates of each of those points can be specified in three different ways: With two lists of the same length, in which the elements of the first list are the horizontal coordinates of the points and the second list are the vertical coordinates, or with a list of two-element lists, each one corresponding to the two coordinates of one of the points, or with a single list that defines the vertical coordinates of the points; in this last case, the horizontal coordinates of the n points will be assumed to be the first n natural numbers.
  5. Contour lines. plot2d ([contour, expr], range_x, range_y, options), where expr is an expression that depends on two variables. range_x and range_y will be lists whose first elements are the names of those two variables, followed by two numbers that set the minimum and maximum values for them. The first variable will be represented along the horizontal axis and the second along the vertical axis. The result will be a set of curves along which the given expression has certain values. If those values are not specified with the option levels, plotd2d will try to choose, at the most, 8 values of the form d*10^n, where d is either 1, 2 or 5, all of them within the minimum and maximum values of expr within the given ranges.

At the end of a plot2d command several of the options described in Plotting Options can be used. Many instances of the 5 types described above can be combined into a single plot, by putting them inside a list: plot2d ([type_1, …, type_n], options). If one of the types included in the list require range_x or range_y, those ranges should come immediately after the list.

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:

  1. Explicit function.
    (%i1) plot2d (sin(x), [x, -%pi, %pi])$
    
    figures/plotting6
  2. Implicit function.
    (%i1) plot2d (x^2-y^3+3*y=2, [x,-2.5,2.5], [y,-2.5,2.5])$
    
    figures/plotting3
  3. Parametric function.
    (%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]])$
    
    figures/plotting11
  4. Set of points.
    (%i1) plot2d ([discrete, makelist(i*%pi, i, 1, 5),
                                [0.6, 0.9, 0.2, 1.3, 1]])$
    
    figures/plotting14
  5. Contour lines.
    (%i1) plot2d ([contour, u^3 + v^2], [u, -4, 4], [v, -4, 4])$
    
    figures/plotting2

Examples using options.

If an explicit function grows too fast, the y option can be used to limit the values in the vertical axis:

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

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], nobox, 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"])$
figures/plotting8

A plot with a logarithmic scale in the vertical axis:

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

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])$
figures/plotting10

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)$
figures/plotting12

A plot of 200 random numbers between 0 and 9:

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

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) display2d:false$
(%i2) with_stdout ("data.txt", for x:0 thru 10 do
                             print (x, x^2, x^3))$
(%i3) data: read_matrix ("data.txt")$
(%i4) plot2d ([discrete, transpose(data)[2], transpose(data)[3]],
  [style,points], [point_type,diamond], [color,red])$
figures/plotting15

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)"])$
figures/plotting16

See also the section about Plotting Options.

Categories: Plotting ·
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],
        nomesh_lines)$
figures/plotting17

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],
         nopalette, [color, magenta])$
figures/plotting18

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])$
figures/plotting19

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 function 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])$
figures/plotting20

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])$
figures/plotting21

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], nolegend)$
figures/plotting22

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], nobox,
    nolegend, [grid, 12, 80], [transform_xy, polar_to_xy])$
figures/plotting23

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, nolegend,
  [transform_xy, spherical_to_xyz], [mesh_lines_color,blue],
  [palette,[gradient,"#1b1b4e", "#8c8cf8"]])$
figures/plotting24

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], nolegend)$
figures/plotting25

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], noztics, [color_bar_tics,1])$
figures/plotting26

See also Plotting Options.

Categories: Plotting ·
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.

Categories: Plotting ·
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 Plotting Options.

Categories: Plotting ·
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]]
Categories: Plotting ·
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.

Categories: Plotting ·

Next: , Previous: , Up: Plotting   [Contents][Index]