Adding traces




From the command window, the most common way to start plt is with a command such as:

plt(x,y)

where x and y contain the data that you want to plot. Of course this is the same as you would have done before being exposed to plt, except that you would have spelled it "plot". This command opens a new axis in a new figure window containing just the single trace defined by the x,y parameter pair. There are many ways to call plt so that multiple traces are defined, and most of these methods are also shared with the native Matlab plot command. These methods are reviewed in the Calling sequence section.

Where plt and plot diverge more noticeably is how you add traces to a figure that has already been created. With plot this is done using the hold on and hold off commands that I think you will recognize as cumbersome after learning how it is done with plt. The more traces you add, the more you will recognize the advantage of the active legend automatically provided by plt, both for identifying the traces and controlling which traces are visible. (Soon you may begin to wonder how you managed without plt.)

Assuming a single trace was defined using the plt command mentioned above, the command:

pltt(x1,y1,'TraceName')

will cause a new trace defined by the x1,y1 pair to appear on the plot. Also a second entry will appear in the TraceID box with the trace name specified in the call to pltt. If you are feeling lazy, you could omit the trace name in the argument list, in which case a default (incrementing) trace name will be used. The more traces you add, the more you will realize that you should have specified the trace names all along.

When you type the plt command in the command window, space will be reserved in the TraceID box for eight additional traces (beyond those defined in the plt command itself) to be added using the pltt command. This is usually enough, but if you go beyond this limit, pltt will overwrite the trace data and TraceID of the previously added trace to make room for the new trace being added. If you anticipate needing to add more than eight traces, you can allocate more space in the TraceID box using the + parameter in the plt argument list. (The + is the last parameter described in the Trace properties section.)

You can also specify the data with a single argument: pltt(d) ... or pltt(d,'TraceName') if you want to specify the trace name.

If d is real this is equivalent to the command: pltt(1:length(d),d)

and if d is complex it's equivalent to the command pltt(real(d),imag(d))

Usually you will probably find it most convenient to add just one trace at a time, however pltt also provides a few ways to add more than one trace at a time. (This is especially useful inside script files). For example, both of these commands:

pltt(x,{y1 y2 y3},{'new1' 'new2' 'new3'});
pltt(x,[y1;y2;y3],{'new1' 'new2' 'new3'});

are equivalent to the three separate commands:

pltt(x,y1,'new1');
pltt(x,y2,'new2');
pltt(x,y3,'new3');

Note that in the 2nd form above, it was assumed that y1,y2,y3 were row vectors. (If they were column vectors they would need to be delimited with spaces or commas in place of the semicolons.)

As before, the data may be specified with a single argument, so:

pltt({d1 d2 d3},{'new1' 'new2' 'new3'});
pltt([d1;d2;d3],{'new1' 'new2' 'new3'});

are equivalent to the three separate commands:

pltt(d1,'new1');
pltt(d2,'new2');
pltt(d3,'new3');

And one last form to consider for when you are adding traces with differing x data. The command:

pltt({x1 x2 x3},{y1 y2 y3},{'new1' 'new2' 'new3'});

is equivalent to these three commands:

pltt(x1,y1,'new1');
pltt(x2,y2,'new2');
pltt(x3,y3,'new3');

In all the commands above with a cell array of trace names, that parameter may be omitted in which case the default trace names will be used. Or the cell array of trace names may be replaced with a single character string in which case all the traced defined by that command will be given the same trace name (useful in a few unusual situations).

It's unusual to need to delete a trace because it is easier to simply click on the trace name in the TraceID box to make the unneeded trace invisible. However in rare situations you may actually want to delete the trace from the plot so that you can later add a new trace in its place (with pltt). You can delete a trace using pltt. As an example, the command:

pltt(-3);

will remove the trace associated with the third trace name in the TraceID box. Later a trace added by a command such as pltt(x1,y1,'new') will be placed in the vacated third position of the TraceID box (assuming that is the first free open slot). Attempting to delete a trace that has already been deleted will have no effect. You can delete any trace regardless of whether it was created with the original plt command or added latter with the pltt command. However pltt can't be used (either for adding or removing traces) unless plt was called from the command line or if the '+',n parameter was used in the plt argument list. (n may be zero if you don't need to add more traces than were originally defined by the plt command.)