Making beautiful plots in IDL

You know how IDL plots can look pretty bad. One day I came across this link. From that day on, I've made consistently nice looking eps figures with IDL. Thanks much, Alfred. I slightly modified the commands given in this link and wrapped it in a proplot.pro file that I call before calling my regular plotting commands.

pro proplot, ps, font_size=font_size, xsize=xsize, ysize=ysize

set_plot, 'ps'

;colors
loadct, 39, /silent
!p.color=0
!p.background=255

;font
!p.font = 0
!p.charsize=3.
if ~keyword_set(font_size) then font_size=5.5

;thickness
!p.thick = 4
!x.thick = 4
!y.thick = 4
!z.thick = 4

;figure sizes
if ~keyword_set(xsize) then xsize = 8.8
margin = 0.15
wall = 0.07
a = 1. - (margin + wall)

if ~keyword_set(ysize) then begin
b = a * 2d / (1 + sqrt(5))
ysize = (margin + b + wall)*xsize
end else b = ysize/8.8 - margin - wall

;plot position
x1 = margin*8.8/xsize
x2 = x1 + a*8.8/xsize
y1 = margin*8.8/ysize
y2 = y1 + b*8.8/ysize
!p.position=[x1,y1,x2,y2]

;device
device, filename=ps, font_size=font_size, /schoolbook, /color, xsize=2.5*xsize, ysize=2.5*ysize, /encapsulated

end


After finishing the plot, you need to close the file and possibly reverse all things you have changed (otherwise your non-PostScript plots will look weird). I wrote a wrapper for that:

pro mypsclose

if (!d.name ne 'PS') then begin
message, 'DEVICE is not set to PS!', /INFO
return
endif

; CLOSE THE POSTSCRIPT DEVICE...
device, /CLOSE_FILE

; SET THE GRAPHICS OUTPUT DEVICE TO X WINDOWS...
set_plot, 'X'
if keyword_set(color) then setcolors,/sys,/sil

!p.font=1

device, retain=2, decomposed=0, /tt_font,set_character_size=[20, 24]

defsysv,'!digits',strtrim(sindgen(10),2)

loadct,39,/silent
!p.background=255
!p.color=0

!p.position=[0.15,0.2,0.92,0.92]
!p.thick = 0.
!x.thick = 0.
!y.thick = 0.
!z.thick = 0.
!p.charsize=0.

end


In IDL,

IDL> proplot, 'testfile.eps'
IDL> plot, ..., xtitle='!C The X Title', ...
IDL> mypsclose


Note that the "!C" in the xtitle is to add a carriage return at the beginning of the line. Otherwise, the title may be too close to the plot (or even on the plot).

Comments

Popular Posts