comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: cGimage, Multiplot with /KEEP_ASPECT_RATIO
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: cGimage, Multiplot with /KEEP_ASPECT_RATIO [message #83280] Tue, 12 February 2013 09:12
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> That's a little convoluted. Just for the record, here is a better
> formulation that takes better advantage of cgAspect.
>
> ;----------------------------------------------------------- --
> img1 = cgDemoData(7)
> img2 = congrid(img1, 360, 180)
> cgDisplay, 900, 450
>
> pos = cgLayout([2,1], OYMargin=[4, 11], OXMargin=[5, 8], XGap=6)
> pos1 = pos[*,0]
> img1pos = cgAspect(Position=pos1, Aspect=img1, Align='top')
> cgImage, img1, CTIndex=3, /AXES, POSITION=img1pos, OPOSITION=op
> cgColorbar, CTIndex=3, /Fit
>
> pos2 = pos[*,1]
> ydiff = op[3] - pos2[3]
> pos2[3] = op[3]
> pos2[1] = pos2[1] + ydiff
>
> img2pos = cgAspect(Position=pos2, Aspect=img2, Align='top')
> cgImage, img2, /AXES, POSITION=img2pos, CTIndex=2, /NoErase
> cgColorbar, CTIndex=2, /Fit
> END
> ;----------------------------------------------------------- --

Now that I look at the code in the light of day, it is even simpler than
that! Try this.

;----------------------------------------------------------- --
img1 = cgDemoData(7)
img2 = congrid(img1, 360, 180)
cgDisplay, 900, 450

pos = cgLayout([2,1], OYMargin=[4, 11], OXMargin=[5, 8], XGap=6)
pos1 = pos[*,0]
img1pos = cgAspect(Position=pos1, Aspect=img1, Align='top')
cgImage, img1, CTIndex=3, /AXES, POSITION=img1pos, OPOSITION=op
cgColorbar, CTIndex=3, /Fit

pos2 = pos[*,1]
img2pos = cgAspect(Position=pos2, Aspect=img2, Align='top')
cgImage, img2, /AXES, POSITION=img2pos, CTIndex=2, /NoErase
cgColorbar, CTIndex=2, /Fit
END
;----------------------------------------------------------- --




--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: cGimage, Multiplot with /KEEP_ASPECT_RATIO [message #83281 is a reply to message #83280] Tue, 12 February 2013 09:06 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> Alright, this was easy enough to do, so I just had Coyote do it. :-)
>
> Find it here:
>
> http://www.idlcoyote.com/programs/cgaspect.pro
>
> And here is how I would use the routine to display these two images with
> colorbars:
>
> ;-------------------------------------------------
> img1 = cgDemoData(7)
> img2 = congrid(img1, 360, 180)
> cgDisplay, 900, 450
>
> pos = cgLayout([2,1], OYMargin=[4, 11])
> cgImage, img1, /KEEP_ASPECT_RATIO, CTIndex=3, $
> /AXES, POSITION=pos[*,0], OPOSITION=op
> cgColorbar, CTIndex=3, /Fit
>
> pos2 = pos[*,1]
> ydiff = op[3] - pos2[3]
> pos2[3] = op[3]
> pos2[1] = pos2[1] + ydiff
>
> img2pos = cgAspect(Position=pos2, Aspect=img2, Align='top')
> cgImage, img2, /AXES, POSITION=img2pos, CTIndex=2, /NoErase
> cgColorbar, CTIndex=2, /Fit
> END
> ;-------------------------------------------------

That's a little convoluted. Just for the record, here is a better
formulation that takes better advantage of cgAspect.

;----------------------------------------------------------- --
img1 = cgDemoData(7)
img2 = congrid(img1, 360, 180)
cgDisplay, 900, 450

pos = cgLayout([2,1], OYMargin=[4, 11], OXMargin=[5, 8], XGap=6)
pos1 = pos[*,0]
img1pos = cgAspect(Position=pos1, Aspect=img1, Align='top')
cgImage, img1, CTIndex=3, /AXES, POSITION=img1pos, OPOSITION=op
cgColorbar, CTIndex=3, /Fit

pos2 = pos[*,1]
ydiff = op[3] - pos2[3]
pos2[3] = op[3]
pos2[1] = pos2[1] + ydiff

img2pos = cgAspect(Position=pos2, Aspect=img2, Align='top')
cgImage, img2, /AXES, POSITION=img2pos, CTIndex=2, /NoErase
cgColorbar, CTIndex=2, /Fit
END
;----------------------------------------------------------- --


Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: cGimage, Multiplot with /KEEP_ASPECT_RATIO [message #83282 is a reply to message #83281] Tue, 12 February 2013 08:31 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

>
> Fab writes:
>
>> Thanks, I adapted your idea in my code and after a few dozens of tries I
>> am satisfied with the output ;-) I won't change anything at the code
>> anymore though!
>
> Here is a programming challenge that will make this very much easier
> next time.
>
> Modify ASPECT (and feel free to rename the new program cgAspect) to
> accept an input position for which it can calculate a final position
> with the correct aspect ratio. This ought to be possible, since cgImage
> can apparently do this. ;-)

Alright, this was easy enough to do, so I just had Coyote do it. :-)

Find it here:

http://www.idlcoyote.com/programs/cgaspect.pro

And here is how I would use the routine to display these two images with
colorbars:

;-------------------------------------------------
img1 = cgDemoData(7)
img2 = congrid(img1, 360, 180)
cgDisplay, 900, 450

pos = cgLayout([2,1], OYMargin=[4, 11])
cgImage, img1, /KEEP_ASPECT_RATIO, CTIndex=3, $
/AXES, POSITION=pos[*,0], OPOSITION=op
cgColorbar, CTIndex=3, /Fit

pos2 = pos[*,1]
ydiff = op[3] - pos2[3]
pos2[3] = op[3]
pos2[1] = pos2[1] + ydiff

img2pos = cgAspect(Position=pos2, Aspect=img2, Align='top')
cgImage, img2, /AXES, POSITION=img2pos, CTIndex=2, /NoErase
cgColorbar, CTIndex=2, /Fit
END
;-------------------------------------------------


Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: cGimage, Multiplot with /KEEP_ASPECT_RATIO [message #83283 is a reply to message #83282] Tue, 12 February 2013 06:43 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> If this is what you are trying to do, then I would definitely get
> cgLayout involved! Same idea as before, but you will have a lot more
> flexibility to leave room and space for color bars.

I forgot to mention that the /FIT keyword on cgColorbar does a pretty
good job of fitting a color bar to an image or contour plot without you
having to do much calculation. It works well in conjunction with
cgLayout, for example.

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: cGimage, Multiplot with /KEEP_ASPECT_RATIO [message #83284 is a reply to message #83283] Tue, 12 February 2013 06:40 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Fab writes:

> Just by pure curiosity: is this problem (displaying two images of
> different aspect ratios + a colorbar in a line) anyhow easier in NG?

If this is what you are trying to do, then I would definitely get
cgLayout involved! Same idea as before, but you will have a lot more
flexibility to leave room and space for color bars.

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: cGimage, Multiplot with /KEEP_ASPECT_RATIO [message #83285 is a reply to message #83284] Tue, 12 February 2013 06:37 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Fab writes:

> Thanks, I adapted your idea in my code and after a few dozens of tries I
> am satisfied with the output ;-) I won't change anything at the code
> anymore though!

Here is a programming challenge that will make this very much easier
next time.

Modify ASPECT (and feel free to rename the new program cgAspect) to
accept an input position for which it can calculate a final position
with the correct aspect ratio. This ought to be possible, since cgImage
can apparently do this. ;-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: cGimage, Multiplot with /KEEP_ASPECT_RATIO [message #83286 is a reply to message #83285] Tue, 12 February 2013 06:32 Go to previous message
Fabzi is currently offline  Fabzi
Messages: 305
Registered: July 2010
Senior Member
Just by pure curiosity: is this problem (displaying two images of
different aspect ratios + a colorbar in a line) anyhow easier in NG?

On 02/12/2013 03:20 PM, Fab wrote:
Hi David,

Thanks, I adapted your idea in my code and after a few dozens of tries I
am satisfied with the output ;-) I won't change anything at the code
anymore though!

Cheers,

Fabien

On 02/12/2013 02:54 PM, David Fanning wrote:
Fab writes:

In the following I am making two plots with cg* routines.

img1 = cgDemoData(7)
img2 = congrid(img1, 360, 180)
cgDisplay, 900, 400
!P.Multi = [0, 2, 1]
multimargin = [1,1,1,1]
cgImage, img1, MULTIMARGIN=multimargin, /KEEP_ASPECT_RATIO, /AXES
cgImage, img2, MULTIMARGIN=multimargin, /KEEP_ASPECT_RATIO, /AXES
!P.Multi = 0

Nice, but I would like the top limit of the plots being the same
(meaning translate the second plot upwards a bit). I could'nt find an
easy solution. There must be one though! Any thoughts?

POSITION keyword. Heterogeneous positioning of plots is not the forte
of !P.MULTI, who is a guy who craves repetition and homogeneity. :-)

And, since you are asking to keep the aspect ratio, you will have to
be prepared to adjust the position of the second image in Y space.
I would probably try something like this.

;--------------------------------------------------
img1 = cgDemoData(7)
img2 = congrid(img1, 360, 180)
cgDisplay, 900, 400
cgImage, img1, /KEEP_ASPECT_RATIO, /AXES, $
POSITION=[0.05, 0.1, 0.475, 0.90], OPOSITION=op

s = Size(img2, /Dimensions)
imgaspect = Float(s[1])/s[0]

xdist = 0.95-0.525
ydist = (xdist * imgaspect) * 2
pos2 = [0.525, op[3]-ydist, 0.95, op[3]]
cgImage, img2, /AXES, POSITION=pos2, /NoErase
;--------------------------------------------------


Cheers,

David
Re: cGimage, Multiplot with /KEEP_ASPECT_RATIO [message #83287 is a reply to message #83286] Tue, 12 February 2013 06:20 Go to previous message
Fabzi is currently offline  Fabzi
Messages: 305
Registered: July 2010
Senior Member
Hi David,

Thanks, I adapted your idea in my code and after a few dozens of tries I
am satisfied with the output ;-) I won't change anything at the code
anymore though!

Cheers,

Fabien

On 02/12/2013 02:54 PM, David Fanning wrote:
> Fab writes:
>
>> In the following I am making two plots with cg* routines.
>>
>> img1 = cgDemoData(7)
>> img2 = congrid(img1, 360, 180)
>> cgDisplay, 900, 400
>> !P.Multi = [0, 2, 1]
>> multimargin = [1,1,1,1]
>> cgImage, img1, MULTIMARGIN=multimargin, /KEEP_ASPECT_RATIO, /AXES
>> cgImage, img2, MULTIMARGIN=multimargin, /KEEP_ASPECT_RATIO, /AXES
>> !P.Multi = 0
>>
>> Nice, but I would like the top limit of the plots being the same
>> (meaning translate the second plot upwards a bit). I could'nt find an
>> easy solution. There must be one though! Any thoughts?
>
> POSITION keyword. Heterogeneous positioning of plots is not the forte
> of !P.MULTI, who is a guy who craves repetition and homogeneity. :-)
>
> And, since you are asking to keep the aspect ratio, you will have to
> be prepared to adjust the position of the second image in Y space.
> I would probably try something like this.
>
> ;--------------------------------------------------
> img1 = cgDemoData(7)
> img2 = congrid(img1, 360, 180)
> cgDisplay, 900, 400
> cgImage, img1, /KEEP_ASPECT_RATIO, /AXES, $
> POSITION=[0.05, 0.1, 0.475, 0.90], OPOSITION=op
>
> s = Size(img2, /Dimensions)
> imgaspect = Float(s[1])/s[0]
>
> xdist = 0.95-0.525
> ydist = (xdist * imgaspect) * 2
> pos2 = [0.525, op[3]-ydist, 0.95, op[3]]
> cgImage, img2, /AXES, POSITION=pos2, /NoErase
> ;--------------------------------------------------
>
>
> Cheers,
>
> David
>
Re: cGimage, Multiplot with /KEEP_ASPECT_RATIO [message #83288 is a reply to message #83287] Tue, 12 February 2013 05:54 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Fab writes:

> In the following I am making two plots with cg* routines.
>
> img1 = cgDemoData(7)
> img2 = congrid(img1, 360, 180)
> cgDisplay, 900, 400
> !P.Multi = [0, 2, 1]
> multimargin = [1,1,1,1]
> cgImage, img1, MULTIMARGIN=multimargin, /KEEP_ASPECT_RATIO, /AXES
> cgImage, img2, MULTIMARGIN=multimargin, /KEEP_ASPECT_RATIO, /AXES
> !P.Multi = 0
>
> Nice, but I would like the top limit of the plots being the same
> (meaning translate the second plot upwards a bit). I could'nt find an
> easy solution. There must be one though! Any thoughts?

POSITION keyword. Heterogeneous positioning of plots is not the forte
of !P.MULTI, who is a guy who craves repetition and homogeneity. :-)

And, since you are asking to keep the aspect ratio, you will have to
be prepared to adjust the position of the second image in Y space.
I would probably try something like this.

;--------------------------------------------------
img1 = cgDemoData(7)
img2 = congrid(img1, 360, 180)
cgDisplay, 900, 400
cgImage, img1, /KEEP_ASPECT_RATIO, /AXES, $
POSITION=[0.05, 0.1, 0.475, 0.90], OPOSITION=op

s = Size(img2, /Dimensions)
imgaspect = Float(s[1])/s[0]

xdist = 0.95-0.525
ydist = (xdist * imgaspect) * 2
pos2 = [0.525, op[3]-ydist, 0.95, op[3]]
cgImage, img2, /AXES, POSITION=pos2, /NoErase
;--------------------------------------------------


Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: cGimage, Multiplot with /KEEP_ASPECT_RATIO
Next Topic: Re: XYOUTS in 3D

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:28:02 PDT 2025

Total time taken to generate the page: 0.00505 seconds