Discussion:
How do I place an image when I am using !P.Multi?
(too old to reply)
Madhavan Bomidi
2014-06-23 10:16:33 UTC
Permalink
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
David Fanning
2014-06-23 17:16:15 UTC
Permalink
Post by Madhavan Bomidi
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.
Post by Madhavan Bomidi
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.")
Madhavan Bomidi
2014-06-23 20:05:11 UTC
Permalink
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!!
Matthew Argall
2014-06-24 00:40:32 UTC
Permalink
Post by Madhavan Bomidi
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]]
David Fanning
2014-06-24 02:44:24 UTC
Permalink
Post by Matthew Argall
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.")
David Fanning
2014-06-24 02:47:48 UTC
Permalink
Post by David Fanning
But, skipping plots with !P.MULTI is extremely easy, too. Just
manipulate (set) the first element of the !P.MULTI vector. It tells you
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.")
Madhavan Bomidi
2014-06-24 10:34:01 UTC
Permalink
Thanks to both Matthew and David for their examples.

Madhavan
Post by David Fanning
Post by David Fanning
But, skipping plots with !P.MULTI is extremely easy, too. Just
manipulate (set) the first element of the !P.MULTI vector. It tells you
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.")
Madhavan Bomidi
2014-06-24 17:04:34 UTC
Permalink
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
---------------------------------------------------
Matthew Argall
2014-06-24 18:47:31 UTC
Permalink
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.
Madhavan Bomidi
2014-06-24 19:25:04 UTC
Permalink
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
Matthew Argall
2014-06-24 22:49:30 UTC
Permalink
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.
Matthew Argall
2014-06-24 23:07:12 UTC
Permalink
Post by Madhavan Bomidi
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.
Continue reading on narkive:
Loading...