Re: Overplot behalfs strange [message #73262] |
Thu, 04 November 2010 06:04  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
sirvival writes:
> Strange thing is I used /noerase on a different window in my code and
> it still does what I want (display is from
> http://www.astro.uu.se/~piskunov/RESEARCH/REDUCE/display.pro).
> Even if it is in a differnt pro that I run prior.
Yes, any time you do a Plot or Contour command,
a data coordinate system is established and stored
in system variables. It doesn't matter what window
you issue the command in. But, if you rely on
commands outside your program to do things for you,
you will be shocked and awed, sooner rather than
later, at how quickly things can turn bad for you.
And it is usually during the big demo of your new
software to your boss. :-)
> With wrong you mean nlevels?
When you use the NLEVELS keyword in a contour plot,
you are only guaranteed the number of levels won't
exceed N. How many *less* than N you get is a matter
of which phase the moon is in and whether you have
attended religious services in the past 10 days.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: Overplot behalfs strange [message #73265 is a reply to message #73262] |
Thu, 04 November 2010 04:02   |
sirvival
Messages: 18 Registered: August 2010
|
Junior Member |
|
|
On 3 Nov., 17:51, David Fanning <n...@dfanning.com> wrote:
> sirvival writes:
>> I am trying to plot an array and then do an overplot with a contour of
>> the same data.
>
>> My code is like this
>
>> colors
>> y = indgen((ey-5)-(sy+5)+1)+(sy+5)
>> window,5,xsize=1280,ysize=1000
>> loadct,0
>> display,ordim[sx:ex,sy+5:ey-5],x,y,/log,xtitle='Pixel',ytitl e='Pixel'
>> colors
>> contour,ordim[sx:ex,sy+5:ey-5],x,y,nlevels=15,thick=2.5,col= 2,/
>> overplot
>
>> This does not work like I want it too. The contour does not get ploted
>> as it seems.
>
>> But if I do another plot in advance that looks the same but uses the /
>> noerase keyword with contour I get what I am looking for.
>> e.g.
>> window,0
>> display,ordim
>> contour,ordim,nlevels=20,/noerase
>
>> If I close idl it gets "reseted" and I have to do the /noerase plot
>> again to get my plot working.
>
>> Its not an big issue but I wonder whats happening.
>
>> What I want is:
>> http://img841.imageshack.us/img841/9059/contour.jpg
>
> Ah, yes, timely question. I am working on this section
> of my book now. You are going to like it. :-)
>
> The problem you have is that "Display" is probably
> just displaying an image, not setting up a data
> coordinate space. Hence, there is nothing for Contour
> to "overplot" on. No data coordinate space!!
>
> With images, it is typically necessary (because
> image don't create data coordinate spaces in IDL),
> to "draw" a data coordinate space over the top of them.
> We try to do this invisibly, of course, so we usually
> turn the axes completely off. Your commands should be
> something like this:
>
> contour,ordim[sx:ex,sy+5:ey-5],x,y,nlevels=15,thick=2.5,$
> col=2, xstyle=5, ystyle=5, /nodata
> display,ordim[sx:ex,sy+5:ey-5],x,y,/log,xtitle='Pixel',$
> ytitle='Pixel'
> contour,ordim[sx:ex,sy+5:ey-5],x,y,nlevels=15,thick=2.5,$
> col=2,/overplot
>
> Or, you could just continue to use that NOERASE keyword.
> That's what I would probably do. You just need to remember
> to erase your display window before you display your image,
> since I doubt Display remembers to do that for you either.
>
> By the way, you are doing your contour plots all wrong, too. :-)
>
> http://www.dfanning.com/documents/tips.html#CONTOURPLOTTIPS
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Thanks.
Strange thing is I used /noerase on a different window in my code and
it still does what I want (display is from
http://www.astro.uu.se/~piskunov/RESEARCH/REDUCE/display.pro).
Even if it is in a differnt pro that I run prior.
With wrong you mean nlevels?
|
|
|
Re: Overplot behalfs strange [message #73304 is a reply to message #73265] |
Wed, 03 November 2010 09:51   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
sirvival writes:
> I am trying to plot an array and then do an overplot with a contour of
> the same data.
>
>
> My code is like this
>
> colors
> y = indgen((ey-5)-(sy+5)+1)+(sy+5)
> window,5,xsize=1280,ysize=1000
> loadct,0
> display,ordim[sx:ex,sy+5:ey-5],x,y,/log,xtitle='Pixel',ytitl e='Pixel'
> colors
> contour,ordim[sx:ex,sy+5:ey-5],x,y,nlevels=15,thick=2.5,col= 2,/
> overplot
>
>
> This does not work like I want it too. The contour does not get ploted
> as it seems.
>
> But if I do another plot in advance that looks the same but uses the /
> noerase keyword with contour I get what I am looking for.
> e.g.
> window,0
> display,ordim
> contour,ordim,nlevels=20,/noerase
>
> If I close idl it gets "reseted" and I have to do the /noerase plot
> again to get my plot working.
>
> Its not an big issue but I wonder whats happening.
>
> What I want is:
> http://img841.imageshack.us/img841/9059/contour.jpg
Ah, yes, timely question. I am working on this section
of my book now. You are going to like it. :-)
The problem you have is that "Display" is probably
just displaying an image, not setting up a data
coordinate space. Hence, there is nothing for Contour
to "overplot" on. No data coordinate space!!
With images, it is typically necessary (because
image don't create data coordinate spaces in IDL),
to "draw" a data coordinate space over the top of them.
We try to do this invisibly, of course, so we usually
turn the axes completely off. Your commands should be
something like this:
contour,ordim[sx:ex,sy+5:ey-5],x,y,nlevels=15,thick=2.5,$
col=2, xstyle=5, ystyle=5, /nodata
display,ordim[sx:ex,sy+5:ey-5],x,y,/log,xtitle='Pixel',$
ytitle='Pixel'
contour,ordim[sx:ex,sy+5:ey-5],x,y,nlevels=15,thick=2.5,$
col=2,/overplot
Or, you could just continue to use that NOERASE keyword.
That's what I would probably do. You just need to remember
to erase your display window before you display your image,
since I doubt Display remembers to do that for you either.
By the way, you are doing your contour plots all wrong, too. :-)
http://www.dfanning.com/documents/tips.html#CONTOURPLOTTIPS
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: Overplot behalfs strange [message #73409 is a reply to message #73262] |
Thu, 04 November 2010 06:38  |
sirvival
Messages: 18 Registered: August 2010
|
Junior Member |
|
|
On 4 Nov., 14:04, David Fanning <n...@dfanning.com> wrote:
> Yes, any time you do a Plot or Contour command,
> a data coordinate system is established and stored
> in system variables. It doesn't matter what window
> you issue the command in.
Ah ok. If it gets stored as system variable then the behavior makes
sense.
The extra pro was only mentioned by me because thats how I noticed the
"problem" (I used an existing pro and reduced its code for my purpose.
The /noerase was missing therefor. When I compared both pros the only
difference I noticed was the /noerase that was done in the original
prior to the main plot).
> When you use the NLEVELS keyword in a contour plot,
> you are only guaranteed the number of levels won't
> exceed N. How many *less* than N you get is a matter
> of which phase the moon is in and whether you have
> attended religious services in the past 10 days.
Final code (with correct nlevels as shown in your example):
levels = 15
step = (Max(ordim[sx:ex,sy+5:ey-5]) - Min(ordim[sx:ex,sy+5:ey-5])) /
levels
userLevels = IndGen(levels) * step + Min(ordim[sx:ex,sy+5:ey-5])
y = indgen((ey-5)-(sy+5)+1)+(sy+5)
window,5,xsize=1280,ysize=1000
loadct,0
contour,ordim[sx:ex,sy+5:ey-5],x,y,nlevels=15,thick=2.5,col= 2,
xstyle=5, ystyle=5, /nodata
display,ordim[sx:ex,sy+5:ey-5],x,y,/log,xtitle='Pixel',ytitl e='Pixel'
colors
contour,ordim[sx:ex,sy
+5:ey-5],x,y,xtitle='Pixel',ytitle='Pixel',levels=userLevels ,thick=2.5,col=2,/
overplot
write_jpeg,'contour.jpg',tvrd(true=1),true=1,quality=100
Thx again
|
|
|