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

Home » Public Forums » archive » How do I place an image when I am using !P.Multi?
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
How do I place an image when I am using !P.Multi? [message #88810] Mon, 23 June 2014 03:16 Go to next message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Hello,

I have a sky image file (.JPG). I am trying to plot with other subplots.

(a) I get a problem w.r.t the size of the sky image that is displayed (sub-plot#2) in the saved file. I see a very small image at the right top corner. How can I actually fit the image that is read in the exact position dimensions I have defined for the display?

(b) In sub-plot#4 I wanted to actually make a PDF (probability density function) for my data array. Is relative frequency that is displayed with the following code the same? If not, how can I actually obtain only PDF displayed?


Below is the code I wrote: (probably you can use some demo data to understand my problem!)

------------------------------------------------------------ -----
cgPS_Open,FigFileName,FONT=-1, CHARSIZE=0.6

; Setting variables to plot
thick = (!D.Name EQ 'PS') ? 2 : 1 ; Setup variable to the plot

; Display window
cgDisplay,XSIZE=2000,YSIZE=1500 ; Create a map projection space

!P.Multi=[0,2,2] ; 2 columns X 2 rows

pos1 = [0.05,0.49,0.5,0.89]
pos2 = [0.57,0.55,0.92,0.9]
pos3 = [0.07,0.1,0.5,0.40]
pos4 = [0.6,0.1,0.90,0.40]

; Sub-Plot#1



; Sub-Plot#2
READ_JPEG,SkyImgFile,img1,ORDER=1
cgImage,img1,/NOERASE,Position=pos2,/KEEP_ASPECT_RATIO

;Sub-Plot#3


;Sub-Plot#4

cgHistoplot,flux,/Frequency,/OProbability,ProbColorName='red ', $
ProbThick=2,PolyColor='dodger blue', /NAN, DataColorName='navy', $
POSITION=pos4,XTITLE='Flux in W/m^2', Charsize=0.85,$
/LINE_FILL,LINE_THICK=2,/OUTLINE,SMOOTH=1,THICK=2,XRange=[0. 0,1.2], $
FONT=-1,YRange=[0.0,0.5]

!P.Multi=0

cgPS_Close

; Create a PNG file with a width of 1500 pixels
cgPS2Raster,FigFileName,/PNG, Width=1500

-----------------------------------------------------------

Please let me know where I am going wrong!!!

Thanks in advance
Re: How do I place an image when I am using !P.Multi? [message #88813 is a reply to message #88810] Mon, 23 June 2014 10:16 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Madhavan Bomidi writes:

> cgPS_Open,FigFileName,FONT=-1, CHARSIZE=0.6
>
> ; Setting variables to plot
> thick = (!D.Name EQ 'PS') ? 2 : 1 ; Setup variable to the plot
>
> ; Display window
> cgDisplay,XSIZE=2000,YSIZE=1500 ; Create a map projection space
>
> !P.Multi=[0,2,2] ; 2 columns X 2 rows
>
> pos1 = [0.05,0.49,0.5,0.89]
> pos2 = [0.57,0.55,0.92,0.9]
> pos3 = [0.07,0.1,0.5,0.40]
> pos4 = [0.6,0.1,0.90,0.40]
>
> ; Sub-Plot#1
>
>
>
> ; Sub-Plot#2
> READ_JPEG,SkyImgFile,img1,ORDER=1
> cgImage,img1,/NOERASE,Position=pos2,/KEEP_ASPECT_RATIO
>
> ;Sub-Plot#3
>
>
> ;Sub-Plot#4
>
> cgHistoplot,flux,/Frequency,/OProbability,ProbColorName='red ', $
> ProbThick=2,PolyColor='dodger blue', /NAN, DataColorName='navy', $
> POSITION=pos4,XTITLE='Flux in W/m^2', Charsize=0.85,$
> /LINE_FILL,LINE_THICK=2,/OUTLINE,SMOOTH=1,THICK=2,XRange=[0. 0,1.2], $
> FONT=-1,YRange=[0.0,0.5]
>
> !P.Multi=0
>
> cgPS_Close
>
> ; Create a PNG file with a width of 1500 pixels
> cgPS2Raster,FigFileName,/PNG, Width=1500
>
> -----------------------------------------------------------
>
> Please let me know where I am going wrong!!!

Well, you are doing quite a lot of things...I hestitate to use the word
"wrong", but certainly "unnecessarily"...which in combination are giving
you a lot of trouble.

There are still a few people who disagree with me, but I do think it is
a grave error to use !P.MULTI and the POSITION keyword at the same time.
If it is not "wrong", then it is certainly responsible for weeks, if not
months, of head scratching. It wouldn't surprise me to learn that just
removing the position keywords allowed you to muddle through with these
plots in some form you could live with.

You set the plot up like this:

> cgPS_Open,FigFileName,FONT=-1, CHARSIZE=0.6
>
> ; Setting variables to plot
> thick = (!D.Name EQ 'PS') ? 2 : 1 ; Setup variable to the plot
>
> ; Display window
> cgDisplay,XSIZE=2000,YSIZE=1500 ; Create a map projection space

This may be exactly what you want, but there is usually no need for all
this. cgPS_Open will do all the character sizing and changing of line
thicknesses for you if you just get out of its way. I've always found it
to go a great job with this, but there are people who like to tweak it.
You may be one of them.

I'm not sure exactly what you are doing with cgDisplay, but I can assure
you it is NOT creating a PostScript page that is 2000 by 1000 pixels in
size, which seems your intention here. I'm on vacation and so can't test
this readily this morning, but I suspect it is simply giving you a
PostScript "page" that has this aspect ratio. That is it's normal job in
a PostScript file.

I'm not sure why you are using a NOERASE keyword on the cgImage call,
but that might really mess up your following histogram, if you are using
!P.Multi to set the position. cgImage will do the right thing when using
it with !P.Multi without having to manipulate it in any way.

If you want to fill up the !P.Multi position space with your image,
don't set the KEEP_ASPECT keyword. If you do set the keyword, it will
fill the space while keeping the aspect ratio. If you want the image to
fill less of the space, use the MULTIMARGIN keyword. The image is really
small right now because you are giving it so many contradictory messages
it doesn't know if it is coming or going.

Good luck with this!

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thos speakest truth.")
Re: How do I place an image when I am using !P.Multi? [message #88814 is a reply to message #88813] Mon, 23 June 2014 13:05 Go to previous messageGo to next message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Hello David,
Thanks for your brief explanation. I have solved my problem.

I always have confusion using !P.Multi. How can I actually adjust the length and width of my figure if I don't use 'Position' keyword when I am using !P.Multi?

Can you provide some insight and examples? Suppose I want to plot 100 subplots with 10 columns and 10 rows, where I have only 99 to plot and 1 is missing.
If I want to adjust the 99th plot to occupy the 100th plot space also, then how !P.Multi can do this?

Thanking you in advance.
Have a nice vacation!!
Re: How do I place an image when I am using !P.Multi? [message #88816 is a reply to message #88814] Mon, 23 June 2014 17:40 Go to previous messageGo to next message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
> If I want to adjust the 99th plot to occupy the 100th plot space also, then how !P.Multi can do this?

I am not David, but you can use cgLayout to do this easily.

positions = cgLayout([10,10])
pos99 = positions[*,98]
pos100 = positions[*,99]
merged_pos = [pos99[0], pos99[1], pos100[2], pos100[3]]
Re: How do I place an image when I am using !P.Multi? [message #88817 is a reply to message #88816] Mon, 23 June 2014 19:44 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Matthew Argall writes:

> I am not David, but you can use cgLayout to do this easily.
>
> positions = cgLayout([10,10])
> pos99 = positions[*,98]
> pos100 = positions[*,99]
> merged_pos = [pos99[0], pos99[1], pos100[2], pos100[3]]

Yes, as Matthew suggests, cgLayout is a more powerful alternative to the
!P.MULTI system variable as it gives more options for positioning the
plots.

But, skipping plots with !P.MULTI is extremely easy, too. Just
manipulate (set) the first element of the !P.MULTI vector. It tells you
how many plots to plot on a page:

IDL> !P.Multi = [0,4,1]; four plots in a row
IDL> cgPlot, cgDemoData(1) ; first plot
IDL> Print, !P.Multi[0]
3
IDL> cgPlot, cgDemoData(1) ; second plot
IDL> !P.Multi[0] = 1 ; skip third plot
IDL> cgPlot, cgDemoData(1) ; fourth plot
IDL> !P.Multi=0

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thos speakest truth.")
Re: How do I place an image when I am using !P.Multi? [message #88818 is a reply to message #88817] Mon, 23 June 2014 19:47 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> But, skipping plots with !P.MULTI is extremely easy, too. Just
> manipulate (set) the first element of the !P.MULTI vector. It tells you
> how many plots to plot on a page:

Sorry, it tells you how many plots REMAIN to be plotted on the page. Too
many Mai-Tais this afternoon. :-(

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thos speakest truth.")
Re: How do I place an image when I am using !P.Multi? [message #88821 is a reply to message #88818] Tue, 24 June 2014 03:34 Go to previous messageGo to next message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Thanks to both Matthew and David for their examples.

Madhavan

On Tuesday, June 24, 2014 4:47:48 AM UTC+2, David Fanning wrote:
> David Fanning writes:
>
>
>
>> But, skipping plots with !P.MULTI is extremely easy, too. Just
>
>> manipulate (set) the first element of the !P.MULTI vector. It tells you
>
>> how many plots to plot on a page:
>
>
>
> Sorry, it tells you how many plots REMAIN to be plotted on the page. Too
>
> many Mai-Tais this afternoon. :-(
>
>
>
> David
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
>
> Sepore ma de ni thue. ("Perhaps thos speakest truth.")
Re: How do I place an image when I am using !P.Multi? [message #88830 is a reply to message #88821] Tue, 24 June 2014 10:04 Go to previous messageGo to next message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
I tried to do as per the example suggested by Matthew, but I am getting some strange things. I am not able to see any plot. When I see the .ps file, I see multiple pages each page containing 1 smallbox but not plot. Also, the display window is not able to plot all 10 subplots. Can you try with some arbitrary data and let me know where I am going wrong??

-----------------------------------------
cgPS_Open, OutFileName
cgDisplay
positions = cgLayout([10,10]) ; 10 cols x 10 rows

FOR j=0,(ns-1) DO BEGIN

pos = positions[*,j]

cgPlot,uTime,data[j,*],XStyle=1,YStyle=1,Position=pos, $
XRange=[4,20],YRange=[0,1200],Font=-1,LineStyle=0

ENDFOR

cgPS_Close

; Create a PNG file
cgPS2Raster,OutFileName,/PNG
---------------------------------------------------
Re: How do I place an image when I am using !P.Multi? [message #88832 is a reply to message #88830] Tue, 24 June 2014 11:47 Go to previous messageGo to next message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
One point is that if you do not use the NOERASE keyword, each new plot will create a new postscript page.

Here is an example that works...

noerase = bytarr(100) + 1B
noerase[0] = 0B
positions = cgLayout([3,3])
for i = 0, 8 do cgPlot, cgDemoData(1), TITLE='Title', XTITLE='X Title', YTITLE='Y Title', $
NOERASE=noerase[i], POSITION=positions[*,i]


However, I noticed that if you increase the number of columns and rows (e.g. to [4,4] with the default window size), then the margin and gap sizes create a funky position that turns things up-side-down, inside-out, and round-and-round.


positions = cgLayout([4,4])
for i = 0, 15 do cgPlot, cgDemoData(1), TITLE='Title', XTITLE='X Title', YTITLE='Y Title', $
NOERASE=noerase[i], POSITION=positions[*,i]
print, positions[*,0]
0.208333 0.801414 0.166667 0.725793


So, you will have to pick a layout that is reasonable for your window size.
Re: How do I place an image when I am using !P.Multi? [message #88835 is a reply to message #88832] Tue, 24 June 2014 12:25 Go to previous messageGo to next message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Hello Matthew,

Thanks for the examples. I wanted to make a plot similar to http://www.idlcoyote.com/gallery/multiple_image_plot.pro but without images and colorbar. I will use cgPlot for my line plots. I still don't understand if there is a way we can manage margin and gap sizes. For my purpose, I don't need to create so huge plots. Very minimal or no gap between plots is fine. Can I change the plotting window size to fit these all 10 x 10 plots in one page?

Thanks in advance.
Madhavan
Re: How do I place an image when I am using !P.Multi? [message #88836 is a reply to message #88835] Tue, 24 June 2014 15:49 Go to previous messageGo to next message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
You can set the [XY]Gap and [XY]Margin keywords in cgLayout and open a bigger window. Just use the example I gave. If the title is on bottom and the x-title is on top, then you have to do at least one of those those things.
Re: How do I place an image when I am using !P.Multi? [message #88837 is a reply to message #88835] Tue, 24 June 2014 16:07 Go to previous message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
> Can I change the plotting window size to fit these all 10 x 10 plots in one page?

The biggest a postscript page can be is 8.5"x11". If you want something bigger, you have to use cgSnapshot, which does not use intermediate post-script files. Then, you can make the window as big as you want.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: How can I use the shapefiles of a particular country in plotting the country boundaries?
Next Topic: A grid is overlaid on an image

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

Current Time: Wed Oct 08 11:36:08 PDT 2025

Total time taken to generate the page: 0.00568 seconds