### The Maxima on-line user's manual

Algebra Calculator

#### Plot2d

Function: plot2d (<plot>, <x_range>, ..., <options>, ...)

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

Function: 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 should also be a list with two values that correspond to the x and y coordinates of a point.

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 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 or function names.

*Examples:*

```     Plot of a common function:
(%i1) plot2d (sin(x), [x, -%pi, %pi])\$```

If the functions 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])\$`
`          plot2d: some values were clipped.`

The aspect of the plot might be different depending on the plotting program used. For instance, when the plot box is disable, Xmaxima will plot the axes using arrows:

`          (%i1) plot2d ( x^2-1, [x, -3, 3], [y, -2, 10], [box, false],`
`                     [plot_format, xmaxima])\$`

```     A plot with a logarithmic scale:
(%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],
[nticks, 2000]])\$```

A "circle" with two turns, when plotted with only 7 points:

```          (%i1) plot2d ([parametric, cos(t), sin(t), [t, -2*%pi, 2*%pi],
[nticks, 8]])\$```

Plot of a common function together with the parametric representation of a circle. The size of the plot has been adjusted with the x and y options, to make the circle look round and not deformed as an ellipse. These values work well for the Postscript terminal used to produce this plot; you might have to adjust the values for your screen.

```          (%i1) plot2d([[parametric, cos(t), sin(t) ,[t,0,2*%pi],
[nticks, 80]], abs(x)], [x,-2,2], [y, -1.5, 1.5])\$
plot2d: some values were clipped.```

```     A plot of a discrete set of points, defining x and y coordinates
separately:
(%i1) plot2d ( [ discrete, [10, 20, 30, 40, 50],
[.6, .9, 1.1, 1.3, 1.4]] )\$```

The same points shown in the previous example, defining each point separately and without any lines joining the points:

`          (%i1) plot2d([discrete, [[10, .6], [20, .9], [30, 1.1], [40, 1.3],`
`                             [50, 1.4]]], [style, points])\$`

In this 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: transpose ( read_matrix ("data.txt"))\$`
`          (%i3) plot2d ([discrete, data[2], data[3]],`
`                  [style,points], [point_type,diamond], [color,red])\$`

A plot of experimental data points together with the theoretical function that predicts the data:

`          (%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, "pendulums length (cm)"], [ylabel, "period (s)"])\$`

```(%o1)                                true
(%i2) ```

### Related Examples

##### plot2d

cu1:[[0,26],[1,28],[2...

plot2d([discrete,cu1]);

Calculate

##### plot2d

plot2d([discrete, [[1...

Calculate

##### plot2d-sin

f(x) := sin(x^2/21);

plot2d(f(x), [x, 0, 4...

Calculate

##### plot2d

k: -2.0;

SP: 25.0;

T(t) := T0*%e^(k*t)+S...

Calculate

##### plot2d

plot2d (x^3-2*x^2 - 5...

Calculate

##### plot2d

k: -2.0;

SP: 25.0;

T(t) := T0*%e^(k*t)+S...

Calculate

##### plot2d

plot2d(-0.26*x^4+0.42...

Calculate

##### plot2d-solve

f(x):=(x^2 - 3*x^3) /...

solve(f(x)=0);

plot2d([f(x)], [x,-4,...

Calculate

##### plot2d

plot2d([3.52-1.04*x],...

3.52/1.04;

Calculate

##### plot2d-sin

plot2d(x+ sin(x),[x,-...

Calculate