One of Mathematica's strengths is its graphical capability. Sometimes to get proper perspective of a set of numbers you must see it. Other times, you must show something that you have spent a lot of time mastering to someone else who has little time to consider it properly. In both cases, a graph would be a nice way to represent and explore data.

To show a basic two-dimensional graph, one uses the command Plot[function,{variable,min,max}]. So if one wanted to see the graph of x^2+2x-3 between -3 and 3, one would ask Mathematica to evaluate Plot[x^2+2x-3,{x,-3,3}].

Mathematica tries to decide what is important about the drawing and show the most interesting information. You can force Mathematica to draw the graph to your specifications by setting some addional options when you tell it to Plot a graph. If, for example, we wanted to show the graph between -10 and 10 on the y-xis, we would enter Plot[x^2+2x-3,{x,-3,3},PlotRange->{-10,10}].

Plot can also take a list of functions to graph. If you wanted to show the Sin and Cos of x between -Pi and Pi, for example, you could ask Mathematica to Plot[{Sin[x],Cos[x]},{x,-Pi,Pi}].

Graphs in Mathematica can be copied and pasted into Microsoft Office seemlessly, adding to the usefulness of the graphing capabilities of Mathematica. Alternatively, you can use the command HTMLSave["filename.html"] to have Mathematica save an entire workbook as a web page. In this instance, it will turn each part of each cell into a .gif image, ready to be imported into any application or web page. [Some, but not all of the example graphics for this web tutorial were made in this way].

Mathematica can also handle parametric graphs, via ParametricPlot. Since parametric graphs involve two functions, it is necessary to make use of the ability of Mathematica to take a list of functions in the first argument of ParameticPlot. If we wanted to see the plot of the Lissajous figure, x=sin(t) y=sin(4t), we would tell Mathematica ParametricPlot[{Sin[t],Sin[4t]},{t,0,2Pi}].

Discrete data can be displayed with ListPlot. If we wanted to display a plot of the first 11 numbers in the Fibonacci sequence, for example, the following entry in our notebook would give us the proper result:

This isn't terribly easy to read, however, so we might want to make the dots heavier. That can be accomplished by telling ListPlot to alter the AbsolutePointSize of the plot.

If we want to connect the points we just have to ask Mathematica to draw the graph with PlotJoined->True.

Finally, if we want to view the points and the line, we have to use the Show function, which allows us to redisplay previous graphical output with different viewing parameters but without recalculating the data. We could change where the orgin of the axes is, or even remove the axes all together, but we couldn't use Show to give us the plot of the next ten Fibonacci numbers without using ListPlot to generate the data first. In this case we will Show[{Out[20],Out[22]}].

Notice that Show took the liberty of readjusting our axes for us. Otherwise, the result is exactly what we wanted. If we needed to, we could change the axes to be in line with those in the two previous screen shots but for now we wil accept the result.

The last graphical function we will look at is Plot3D, which shows us three dimensional plots of functions with two variables. If you wanted to know what the graph of z=sin(xy) looked like, you could enter Plot3D[Sin[x*y],{x,-Pi,Pi},{y,-Pi,Pi}].

A rather impressive, if somewhat jagged, image. To help make things clearer we can ask Mathematica to work a little harder when making the graph, and to sample more points before drawing. Adding the option PlotPoints->35 will give us a smoother picture.

Smoother but more obscured by the grid on the surface. We can Show this graph again without the mesh for a nicer image still.

Perhaps it would look better with more PlotPoints, but for now that is good enough.

Through exploration of the various graphing functions and the Show function, you should be able to completely control how your graph looks. Now that everything looks pretty, lets get into some common computational functions.

 

Tutorial Home

Table of Contents

About this Site
Previous: HELP! Next: An overview of some commonly used functions for everyday calculation