Advice: Plotting in procedures

The various "plotting" commands do not actually plot anything. Instead, they return a plot structure, and the actual plot is produced when that plot structure is "printed". This is what allows you to produce several plots and then combine them (typically using display ) into one plot, without seeing the individual plots. Normally, when the plotting command is ended by a semicolon, the result of the command is "printed" and you see the plot. However, if the command is placed inside a procedure, and the result of the command is not the last result in the procedure, it will not be printed (unless printlevel is at least 5). The simplest remedy is to use print to explicitly print the result.

A typical case where this arises is in writing a procedure to produce a plot file (in one of the formats that Maple supports, such as jpeg or PostScript. The same principles apply, whether the plot is sent to the screen or a file. So instead of something like

> myproc:= proc()
plotsetup(ps, plotoutput=myfile);
plot(...);
plotsetup(inline);
end;

you should use

> myproc:= proc()
plotsetup(ps, plotoutput=myfile);
print(plot(...));
plotsetup(inline);
end;

See also:

plot , print , printlevel

Maple Advisor Database, R. Israel 1998