X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 20 Aug 2015 10:31 PM by  anon
Plot and Legend problem
 3 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:32
New Member


--
20 Aug 2015 10:31 PM
    I encountered this problem in my project, not quite sure it is due to my mistake or my system/environment or IDL bug. I plotted charts on a widget_window, and draw a legend on it. It works fine if I don't touch the legend. However, if I move the legend window to another place. Then redraw the chart will cause an error saying: % Unable to invoke method on NULL object reference: )>. % Execution halted at: TESTAPP_EVENT 27 /home/MyProject/TestApp.pro I extract the problematic portion of the code and put it here. Running the code, click on the [plot] button or [bar plot] will active a plotting function, and execute well if I don't move the legend. After moved the legend window, then click on the buttons will lead to an error. My configure is IDL8.4, Debian Wheezy, Dell 64bits desktop. Here is the code and hope someone can give me some advice, thanks in advance. ;;;;;;;; code: TestApp.pro PRO TestApp_Event, ev WIDGET_CONTROL, ev.ID, GET_UVALUE=uval CASE uval OF 'goplot' : BEGIN WIDGET_CONTROL, ev.TOP, GET_UVALUE=ptrwin drawwin = *ptrwin drawwin.select drawwin.erase xx = findgen(10); cxx = cos(xx) sxx = sin(xx) p1 = PLOT(sxx, THICK=2, axis_style=2, Color='red', dim=[450,400], symbol='+', /current, name='sin') p2 = PLOT(cxx, THICK=2, axis_style=2, Color='blue',/overplot, symbol='D', /current, name='cos') yleg = max(cxx) xleg = n_elements(xx) leg = LEGEND(target=[p1, p2], /data, /auto_text_color, position=[xleg,yleg]) END 'gobarplot' : BEGIN WIDGET_CONTROL, ev.TOP, GET_UVALUE=ptrwin drawwin = *ptrwin drawwin.select drawwin.erase xx = findgen(10); cxx = cos(xx) sxx = sin(xx) p1 = BARPLOT(sxx, index=0, NBARS=2, fill_color='green', dim=[450,400], /current, name='sin') p2 = BARPLOT(cxx, index=1, NBARS=2, fill_Color='orange',/overplot, /current, name='cos') yleg = max(cxx) xleg = n_elements(xx) leg = LEGEND(target=[p1, p2], /data, /auto_text_color, position=[xleg,yleg]) END 'goclose' : WIDGET_CONTROL, ev.top, /DESTROY ENDCASE END PRO TestApp on_error, 2 DEVICE, RETAIN=2, DECOMPOSED=0 base = WIDGET_BASE(/COLUMN, XSIZE=500, YSIZE=550) plotbase = widget_base(base, /row, xsize = 500, ysize=500) drawWin0 = WIDGET_WINDOW(plotbase, UVALUE='DRAW0', UNAME='DRAW0', ysize = 500, xsize=500) consbase = WIDGET_BASE(base, /ROW, XSIZE=500, YSIZE=30) plotbutton = widget_button(consbase, VALUE='Plot', UVALUE='goplot') barplotbutton = widget_button(consbase, VALUE='Bar Plot', UVALUE='gobarplot') closebutton = widget_button(consbase, VALUE='Close', UVALUE='goclose') WIDGET_CONTROL, base, /REALIZE WIDGET_CONTROL, drawWin0, GET_VALUE = gDraw WIDGET_CONTROL, base, set_uvalue=ptr_new(gDraw) XMANAGER, 'TestApp', base, /NO_BLOCK END ;;;;;;;; end of code: TestApp.pro

    Deleted User



    New Member


    Posts:32
    New Member


    --
    24 Aug 2015 09:23 PM
    I narrow down the problem a bit. I only need to click on a label on the legend, so that it become focus. Then the problem will occur. Not necessary to move the legend. Could someone help me or suggest a work around? Thanks very much in advance.

    Zachary Norman



    Basic Member


    Posts:173
    Basic Member


    --
    25 Aug 2015 02:27 PM
    Hi Huang Su, It looks like there is an object being referenced in the call to plot that doesn't exist any more, but this error does not actually do anything. If you press the resume button when you hit the error, then the code runs just fine. To work around this, you can create a small catch statement that will run the code again which solves the problem. Here is how you would implement the catch to bypass the error: PRO TestApp_Event, ev WIDGET_CONTROL, ev.ID, GET_UVALUE=uval Catch, errorStatus IF (errorStatus ne 0) then begin MESSAGE, /RESET GOTO, case_start ENDIF case_start: CASE uval OF 'goplot' : BEGIN WIDGET_CONTROL, ev.TOP, GET_UVALUE=ptrwin drawwin = *ptrwin drawwin.select drawwin.erase xx = findgen(10); cxx = cos(xx) sxx = sin(xx) p1 = PLOT(sxx, THICK=2, axis_style=2, Color='red', dim=[450,400], symbol='+', current = drawwin, name='sin') p2 = PLOT(cxx, THICK=2, axis_style=2, Color='blue',/overplot, symbol='D', current = drawwin, name='cos') yleg = max(cxx) xleg = n_elements(xx) leg = LEGEND(target=[p1, p2], /data, /auto_text_color, position=[xleg,yleg]) END 'gobarplot' : BEGIN WIDGET_CONTROL, ev.TOP, GET_UVALUE=ptrwin drawwin = *ptrwin drawwin.select drawwin.erase xx = findgen(10); cxx = cos(xx) sxx = sin(xx) p1 = BARPLOT(sxx, index=0, NBARS=2, fill_color='green', dim=[450,400], /current, name='sin') p2 = BARPLOT(cxx, index=1, NBARS=2, fill_Color='orange',/overplot, /current, name='cos') yleg = max(cxx) xleg = n_elements(xx) leg = LEGEND(target=[p1, p2], /data, /auto_text_color, position=[xleg,yleg]) END 'goclose' : WIDGET_CONTROL, ev.top, /DESTROY ENDCASE END PRO TestApp on_error, 2 DEVICE, RETAIN=2, DECOMPOSED=0 base = WIDGET_BASE(/COLUMN, XSIZE=500, YSIZE=550) plotbase = widget_base(base, /row, xsize = 500, ysize=500) drawWin0 = WIDGET_WINDOW(plotbase, UVALUE='DRAW0', UNAME='DRAW0', ysize = 500, xsize=500) consbase = WIDGET_BASE(base, /ROW, XSIZE=500, YSIZE=30) plotbutton = widget_button(consbase, VALUE='Plot', UVALUE='goplot') barplotbutton = widget_button(consbase, VALUE='Bar Plot', UVALUE='gobarplot') closebutton = widget_button(consbase, VALUE='Close', UVALUE='goclose') WIDGET_CONTROL, base, /REALIZE WIDGET_CONTROL, drawWin0, GET_VALUE = gDraw WIDGET_CONTROL, base, set_uvalue=ptr_new(gDraw) XMANAGER, 'TestApp', base, /NO_BLOCK END

    Deleted User



    New Member


    Posts:32
    New Member


    --
    26 Aug 2015 04:21 AM
    Thanks Zach for providing the work around.
    You are not authorized to post a reply.