David Fanning wrote:
> David Jackson writes:
>
>
>> Unlike the plot command, when I use the plots command and then re-use it
>> with new data, the old data remains on the graph. While I am rather fond of
>> the old data, I would like prefer it not be there. There doesn't appear to
>> be an option for plots that will erase the old data first. Is there a
>> simple way of clearing this data?
>
>
> In simple situations, you just call the PLOT command again,
> with the NODATA keyword set. Then draw your data with PLOTS.
>
> Sometimes this flashes more than you would like, so then you
> resort to smoke and mirrors and use the DEVICE, COPY technique
> with a pixmap.
>
> Make a pixmap the same size as your window. Draw the PLOT without
> data into it. Use DEVICE with the COPY keyword to erase the display
> window with the contents of the pixmap window. Then do your
> PLOTS onto the display window. Very fast, very little flashing.
> This is the way the pros do it. :-)
>
> Cheers,
>
> David
Here's an example of the DEVICE, COPY=[...] technique that David
describes. Just compile and run the procedure. Once the widget is
realized, move the mouse over the image on the left to update the plot
on the right. I see no flashing at all.
Ben
*****START
;-----
; event
;-----
PRO WheresMyWidgetEvent, ev
;get the stuff out of the bucket
WIDGET_CONTROL, ev.top, GET_UVALUE = myStuff, /NO_COPY
;first copy the 'original data' to the image display
;then draw a line across at the cursor location
Widget_Control, myStuff.draw0_ID, Get_Value = win0
WSET, win0
DEVICE, COPY = [0,0,myStuff.sz[0],myStuff.sz[1], 0,0, myStuff.pix0]
PLOTS, [0, myStuff.Sz[0]], [ev.Y, ev.Y], /DEVICE
;now copy the 'baseline' chart to the chart display
;then plot the image values across
;
;**** NOTE **** we only know where to draw this because
;we saved a reference to the widget in the bucket
Widget_Control, myStuff.draw1_ID, Get_Value = win1
WSET, win1
DEVICE, COPY = [0,0,myStuff.sz[0],myStuff.sz[1], 0,0, myStuff.pix1]
OPLOT, LINDGEN(myStuff.Sz[0]), myStuff.image[*,ev.y]
;put you important things back in the bucket
WIDGET_CONTROL, ev.top, SET_UVALUE = myStuff, /NO_COPY
END
;------
; main
;------
PRO WheresMyWidget
;make a base widget with 2 draw widgets, one forand image and one for
;a plot... only the widget withg the image will generate events
tlb = widget_base(column = 2)
sz = [200,200]
draw0_ID = widget_draw(tlb, $
MOTION_EVENTS = 1, $
XSIZE = sz[0], YSIZE = sz[1], $
EVENT_PRO = 'WheresMyWidgetEvent')
draw1_ID = widget_draw(tlb,$
XSIZE = sz[0], YSIZE = sz[1])
;pop the widget up
WIDGET_CONTROL, tlb, /Realize
;set the image widget up for drawing
;show the image
;and make the 'refresh' copy on the pixmap
Widget_Control, draw0_ID, Get_Value = win0
WSET, win0
image = DIST(sz)
TV, BYTSCL(Image)
;make a pixmap window for each widget -
;these are used to 'refresh' the widgets
;before we draw on them
WINDOW, xsize = sz[0], ysize = sz[1], /PIXMAP,/FREE
pix0 = !D.window
WSET, pix0
DEVICE, COPY = [0,0,sz[0],sz[1], 0,0, win0]
;set the chart widget up for drawing
;show the chart (without any data yet)
;and make the 'refresh' copy on the pixmap
Widget_Control, draw1_ID, Get_Value = win1
WSET, win1
PLOT, [0,Sz[0]], [0,MAX(image)], $
XTITLE = 'Image Column', $
YTITLE = 'Image Value', $
/NODATA
WINDOW, xsize = sz[0], ysize = sz[1], /PIXMAP, /FREE
pix1= !D.window
WSET, pix1
DEVICE, COPY = [0,0,sz[0],sz[1], 0,0, win1]
;gather your things to put in the TLB's bucket
;and store them
myStuff = $
{Draw0_ID: draw0_ID, $
Draw1_ID: draw1_ID, $
Pix0: pix0, $
Pix1: pix1, $
SZ: sz, $
Image: Image}
WIDGET_CONTROL, tlb, SET_UVALUE = myStuff, /NO_COPY
XMANAGER, 'wheresmywidget', tlb
END
****END
|