Re: idl plot window disappearances [message #77319 is a reply to message #77318] |
Tue, 23 August 2011 13:47   |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
On 8/23/11 2:54 PM, desertdryad wrote:
> Hi folks -
>
> I'm a bit ew to IDL programming (but not to programming in general)
> and I have an issue that has me perplexed. I am trying to write a
> simple bit of code, where a plot is drawn and a user is prompted
> whether or not they want to accept a curve fit drawn on said plot, or
> attempt another set of fitting parameters. However, the plot window
> mysteriously vanishes the minute the prompt (from a 'read' command) is
> executed. So, one cannot decide whether to accept the curve fit,
> since it becomes invisible (the plot window simply goes blank). I
> have set 'retain=2' to no avail. How do I fix?
>
> Here is a code snippet:
>
> repeat begin
>
> read, mincurve, prompt='enter MINimum X axis value from the CDF over
> which to curvefit:'
> read, maxcurve, prompt='enter MAXimum X axis value from the CDF curve
> over which to curvefit:'
> print, mincurve, maxcurve
>
> ; now, call the curvefit routine to fit the line from min to max
>
> p = minmaxfit(binnorm, histog[0,*], mincurve, maxcurve)
> print, '0 intercept is at: ', p[0]
>
> ;graph that line!
> x = fltarr(51)
> y = fltarr(51)
> inc=maxcurve/50
> ;print, mincurve, maxcurve, (maxcurve)/40
> for i = 0, 50 do begin
> x[i]=inc*i
> y[i] = (p[1]*x[i]) + p[0]
> ;print, x[i], y[i]
> endfor
>
> cgplot, x, y, color='red', /overplot
> yesorno = ' '
> read, yesorno, prompt='Do you want to use this intercept value (y or
> n)?'
>
> endrep until yesorno EQ 'y'
On an unrelated note, my IDL eyes cringe at that FOR loop. ;-) Here's
an easier version of the paragraph under ";graph that line!"
nx = 51
x = findgen(nx) / (nx-1)
y = p[1]*x + p[0]
-Jeremy.
|
|
|