# Overplotting Data on !P.MULTI Plots

**QUESTION:** I would like to draw a number of plots with the !P.MULTI system variable. Then I would
like to add more data to each plot as time goes by. The trouble is, I do not know how to tell IDL to go back to the *n*th plot and overplot the new data there. Can this be done in IDL?

** ANSWER:** But, of course! The reason !P.MULTI is used to set up multiple plots on a page
is that it relieves the user of a lot of bookkeeping about
where to place the plot axes, how big to make the plot characters,
etc. In fact, !P.MULTI sets a lot of fields in the !P, !X, and !Y
system variables to do its job.

If you wish to overplot data on a plot other than the last one that has been created with !P.MULTI then you have to know how to restore these !P.MULTI-manipulated fields to their original values when the plot was created. In practice this means saving the !P, !X and !Y system variables after every plot, so they can be restored for the plot of interest.

Here is an example for three plots, in which I overplot new data on the second plot after drawing all three originally. The method applies to any one of the three original plots. Click here to download the example program.

cgDisplay, 900, 500 !P.Multi = [0, 3, 1] ; Draw the first plot. Keep info. cgPLOT, cgDemoData(17) p1 = !P & x1 = !X & y1 = !Y ; Draw the second plot. Keep info. cgPLOT, cgDemoData(17) p2 = !P & x2 = !X & y2 = !Y ; Draw the third plot. Keep info. cgPLOT, cgDemoData(17) p3 = !P & x3 = !X & y3 = !Y !P.Multi = 0 ; Restore Plot2 info and overplot on the second plot. !P = p2 & !X = x2 & !Y = y2 cgPLOT, cgDemoData(17), Color='red', /Overplot

Overplotting on any of the three plots is now just a matter of restoring the appropriate system variables.

Last Updated 14 March 1997