This is documentation for Mathematica 4, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
Wolfram Research, Inc.

ContentsSpecial Topic: How Graphics Are Output

1.9.1 Basic Plotting

Basic plotting functions.

This plots a graph of as a function of from 0 to .

In[1]:= Plot[Sin[x], {x, 0, 2Pi}]


You can plot functions that have singularities. Mathematica will try to choose appropriate scales.

In[2]:= Plot[Tan[x], {x, -3, 3}]


You can give a list of functions to plot.

In[3]:= Plot[{Sin[x], Sin[2x], Sin[3x]}, {x, 0, 2Pi}]


To get smooth curves, Mathematica has to evaluate functions you plot at a large number of points. As a result, it is important that you set things up so that each function evaluation is as quick as possible.

When you ask Mathematica to plot an object, say f, as a function of x, there are two possible approaches it can take. One approach is first to try and evaluate f, presumably getting a symbolic expression in terms of x, and then subsequently evaluate this expression numerically for the specific values of x needed in the plot. The second approach is first to work out what values of x are needed, and only subsequently to evaluate f with those values of x.

If you type Plot[f, x, xmin, xmax] it is the second of these approaches that is used. This has the advantage that Mathematica only tries to evaluate f for specific numerical values of x; it does not matter whether sensible values are defined for f when x is symbolic.

There are, however, some cases in which it is much better to have Mathematica evaluate f before it starts to make the plot. A typical case is when f is actually a command that generates a table of functions. You want to have Mathematica first produce the table, and then evaluate the functions, rather than trying to produce the table afresh for each value of x. You can do this by typing Plot[Evaluate[f], x, xmin, xmax].

This makes a plot of the Bessel functions with running from to . The Evaluate tells Mathematica first to make the table of functions, and only then to evaluate them for particular values of x.

In[4]:= Plot[Evaluate[Table[BesselJ[n, x], {n, 4}]],

{x, 0, 10}]


This finds the numerical solution to a differential equation, as discussed in Section 1.6.4.

In[5]:= NDSolve[{y'[x] == Sin[y[x]], y[0] == 1}, y, {x, 0, 4}]


Here is a plot of the solution. The Evaluate tells Mathematica to first set up an InterpolatingFunction object, then evaluate this at a sequence of x values.

In[6]:= Plot[Evaluate[ y[x] /. % ], {x, 0, 4}]


Methods for setting up objects to plot.

ContentsSpecial Topic: How Graphics Are Output