Update Data in the Graphic Function
QUESTION: I'd like to update the image data in an IDL 8.0 Image or Plot graphic function. What's the correct way to do this?
I've been doing this.
a = dist(256) b = -1 im = image(a) im = image(b,/OVERPLOT)
This works, but it feels wrong, and it seems to me I'm just stacking one image on top of the other. I was expecting to be able to do something like this, but this code doesn't seem to work.
im = image(a) im.Data = bAm I missing something?
ANSWER: I think you have the right idea here, but you are hampered by incomplete documentation. What you want is the undocumented PutData method, like this.
im = image(a) im.PutData, b
The same PutData method works for plots and other types of IDL 8 graphics, since this method is inherited from the Graphic object class. Note, however, that it only takes (currently) a single variable. As a result, only the absissa changes when passed a single vector.
To change both coordinates (or all three for a 3D plot), you have to pass a single 2xN (or 3xN) variable. For example, consider this plot.
x = Indgen(100) y = Indgen(100) p = Plot(x, y)
If you wanted to change the dependent data, you can do this.
p.PutData, y^2
If you now wanted to change the independent data vector x, and tried this:
p.PutData, x+100
You might be surprised to see the Y (or dependent) data axis change!
To change both axes at the same time, you must do this.
p.PutData, Transpose([[x+100], [y^2]])
Version of IDL used to prepare this article: IDL 8.0
Copyright © 2010 David W. Fanning
Written 28 September 2010
Updated 5 October 2010