Go to the previous, next section.

# A simple plot

Let us assume that you have a file called `mydata`, which looks like this:

```This is an example file

1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
6 36 216
7 49 343
8 64 512
```

SM has a history mechanism, so first type `DELETE 0 10000` to tell SM to forget any commands that it has remembered. Then choose a device to plot on. You do this with a command like `dev tek4010`. If you don't know what to call your terminal, use the `LIST DEVICE` command, ask some local expert, look at the description of `DEVICE`, or (if desperate) read the manual (see section The Stdgraph Graphics Kernel). You'll know that you have succeeded if typing `BOX` draws a box.

You should now have successfully chosen a graphics terminal. To actually plot something, use the following set of commands. The text after the `#` is a comment, you don't have to type this (or the `#`).

```DATA mydata             # Specify desired datafile
LINES 3 100             # Choose which lines to use
READ { ii 2 iii 3 2     # Read column 2 into `ii' and 3 into `iii'
LIMITS i ii             # Choose limits, based on i and ii
BOX                     # Draw the axes
PTYPE 4 0               # Choose square point markers
POINTS i ii             # Plot i against ii
CONNECT i ii            # and connect the points
XLABEL This is i        # Label the X-axis
YLABEL This is ii       # And the Y
```

You should now have a graph. If you had wanted to plot the third column instead of the second you could have typed `LIMITS i iii POINTS i iii` instead. And of course you could plot `ii` against `iii` as a third alternative. You were not limited to only use squares as markers or solid lines to connect them - see `PTYPE` and `LTYPE` for details.

If you want a logarithmic plot, SM makes that easy for you. You can take logs of a vector using the `LG` (or `LN`) commands on vectors; try it - ```SET x=1,10 SET y=x**3 set ly=LG(y) LIMITS x ly CON x ly box```. You might have wanted the axes to reflect the fact that you had logged the y axis. The `TICKSIZE` command allows you to do this, and this is in fact the commonest use of it. Try `TICKSIZE 0 0 -1 0`, and then repeating the x-y plot.

What if you want hard copy of your hard-earned graph? There is a command (actually a macro) called `playback` which will repeat all the commands that you have typed. Type `ERASE` to clear the screen, then `HISTORY` to see the commands that you have issued. You probably don't want the `ERASE` command to be repeated, so type `DELETE` to delete it@footnote #{There is a macro `era` defined as ```DELETE HISTORY ERASE``` that wouldn't have appeared on the list in the first place, similarly `lis` is like `HISTORY` but won't appear on the list of commands. As an alternative, you can use the macro `set_overload` to make lowercase `erase` the same as `DELETE HISTORY erase`, along with a number of other changes. This could be confusing for neophytes! See "overloading"}.

If there are any other mistakes use `DELETE m n` to delete the lines m to n containing them. Now type `playback` and your plot should reappear. But we wanted a hardcopy, so type `dev laser lqueue` (or whatever your friendly Guru recommends as a hardcopy device), then `playback`. This time, those plotting commands will appear on the laser printer not your terminal. To make them actually appear, type `hardcopy` or issue another ``` dev``` command. Be sure to say `dev tek4010` (or whatever device you chose) before you read any more of this document. It is possible to edit the playback buffer, rather than simply deleting lines from within it. The section on `examples' describes how to do this.

In fact, the same plot could have been produced from a data file which just contained the first column. After saying `READ i 1`, you could have said `SET ii = i*i SET iii = i**3` and proceeded from there, or even skipped the file altogether by saying `set i = 1,8` instead of `READ`ing it at all. Such possibilities, and a good deal more, are described in greater detail in the rest of this manual.

What we just did was to define a simple `macro', in this case the special one called `all` which `playback` manipulates. A more explicit use of a macro would be to define a macro to square a vector, that is to square each element of a vector. To do this say @footnote *{It is usually easier to use SM's editor to create macros, try `ed square` or read on.}@br

```MACRO square 2 { SET \$1 = \$2*\$2 2
```
So to calculate the vector `ii` we could now say @br
```square ii i
```
which is the same as saying@br
```SET ii = i*i
```
So now that you have met macros, how do you save them? The simplest and least reliable way is to use SM's history, and hope that the next time that you use SM it remembers the `MACRO` command that you used to define `square`, so you can re-issue it. (Try exiting SM, then starting it up again and typing `HISTORY`, then `^nnn` where is the number which is next to the desired command in the resulting list.)

A brute force way is to say `SAVE filename` which will save almost all of your SM environment, to be recovered using the `RESTORE filename` command at some later time, or later SM session. Specifically, `SAVE` will save all your macros, variables, and vectors, along with your history buffer. This is a very convenient way in practice but it does mean that you tend to carry around lots of long-forgotten macros, variables, and vectors.

Another way is to write the macros to a disk file, using the `MACRO WRITE` command (see `Macros'). Then you can retrieve your macros with `MACRO READ`. You should note that your macro `all` will simply be a macro - to put it onto the history list say `DELETE 0 10000 WRITE HISTORY all`. (Of course, you could write a macro to do this for you). Maybe saving your playback buffer is something better done with `SAVE`, which will restore your playback buffer, while preparing files of useful macros is a use for `MACRO READ`. Once the idea of macros gets into your blood, you can of course use an editor to create your own files of macros, to be read with `MACRO READ`.

Go to the previous, next section.