How do I place an image when I am using !P.Multi? [message #88810] |
Mon, 23 June 2014 03:16  |
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   |
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 #88817 is a reply to message #88816] |
Mon, 23 June 2014 19:44   |
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 #88830 is a reply to message #88821] |
Tue, 24 June 2014 10:04   |
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   |
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 #88837 is a reply to message #88835] |
Tue, 24 June 2014 16:07  |
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.
|
|
|