# Making Fonts Better in IDL Postscript Output

by on April 23, 2009

We’ve all seen it before, illegible labels on a figure in a paper or talk. I don’t know how to remedy this problem in SuperMongo or other popular plotting programs, but I do in IDL. I’ve addressed the topic of postscript output on my IDL figures page but in this post I’m just going to focus on the issue of figure size and fonts. Symbols, line thickness, and colors will be discussed in future posts.

BAD: 18 cm across and vector font

BETTER: 9 cm across and Postscript font

### Make the figure close to the actual printed size

First thing, size matters. That old manuscript preparation document that said figures should fill a letter-sized page is misguided. No matter what type of font you use, if the text size looks right when the figure is 8 inches across, it will be too small when printed as a single column figure only 9 cm across. The BAD figure above is designed at 18 cm across while the BETTER one is 9 cm. Notice the difference in font size. (Charsize was not specified for either plot.) Design the figures to be tiny from the beginning and no further adjustments to the font size will be necessary for either publications or talks.

When these “small from the start” figures are blown up to fill a letter-sized page (i.e., in Latex preprint mode), the fonts might seem too large and look funny to your eye but, since it ensures that nobody will ever have trouble reading your axis labels, you should just get used to it.

aspect_ratio=1.5 ;rectangle device, xsize=9, ysize=xsize/aspect_ratio

### Use Postscript instead of Vector fonts

Inevitably, when a figure is illegible during a talk, a vector (Hershey) font was used instead of a Postscript font. For the purposes of 2D figures, the relevant difference is that vector fonts are thin and have a tendency to disappear while Postscript fonts are thick. The above BAD figure uses the default vector font while the BETTER one uses a Postscript font.

It’s so simple to switch from vector to device fonts! All you need is !p.font=0. While you’re at it, you might as well specify Helvetica for good measure even though, as far as I can tell, it’s the default Postscript typeface.

set_plot, 'ps' !p.font=0 device, /helvetica ; a classic sans-serif font

Everything you ever wanted to know about fonts in IDL is in the Reference Guide.

### Putting it together

aspect_ratio=1.5 xsize=9 ysize=xsize/aspect_ratio set_plot, 'ps' !p.font=0 device, filename='fig_better.eps', encapsulated=1, /helvetica device, xsize=xsize, ysize=ysize plot, a, b, xtitle='X Title', ytitle='Y Title' device, /close set_plot, 'x' !p.font=-1

Know how to get nice legible fonts in other plotting programs? Share it in the comments.

1 Trent April 28, 2009 at 12:52 am

What I *really* want is to be able to make the solar symbol with Postscript fonts. MSun looks ghetto.

Regardless, I am basically a PS font user now. Though I would note that you don’t *have* to use PS fonts to make legible fonts. charsize and charthick are quite adequate at making Hershey fonts visible from the back of the auditorium.

2 Tanya April 28, 2009 at 11:00 am

In Supermongo just use the EXPAND and LWEIGHT command liberally and you’ll get the same result. Depending on how you have set up your sm startup file, you will also be able to change your font and special characters on your XLABEL, YLABEL and PUTLABEL commands easily using standard LaTeX notation.
gl

3 Marshall April 29, 2009 at 1:42 pm

Another solution to making better plots with IDL is to just use Python instead. In all seriousness, I seem to be largely stuck in IDL for now myself due to the inertia of legacy code, but I keep trying to switch more of my new stuff over. The vastly improved plotting facilities are one of the best draws for me thus far.

4 kelle April 30, 2009 at 9:33 am

@Trent, getting M_sun symbol is superbly non-trivial. I’m working on it though…

@Marshall, I agree that there is a growing movement towards Python and away from IDL. If you’d like to write a brief “Switchers Guide,” I’d love to post it! I did find this IDL/Python comparison very useful: http://www.iaa.es/~eperez/Python-IDL-comparison.pdf

5 Andrew May 5, 2009 at 10:07 am

Maybe I am missing something about the sun symbol stuff, but I just use the following command in ps fonts (!p.font=0) – make sure you are in the ‘set_plot, ps’

plot, [1,2],[2,1],xtit=’M’ sunsymbol(font=0)

The dot is not perfectly centered but it’s pretty close – maybe not close enough for some

The function is the the IDL astro library and can be found at:

http://idlastro.gsfc.nasa.gov/ftp/pro/plot/sunsymbol.pro

6 kelle May 5, 2009 at 10:18 am

@Andrew, nope you’re not missing anything. I think the sunsymbol command in the astropro library is a kluge and I simply can’t handle the off-center dot.

7 Melissa May 12, 2009 at 1:01 pm

I change fonts in IDL to get the sun symbol – I think the dot is centered here but it’s possible I just don’t have your eagle eyes? so for example:
M!6!X!D!9n!X!N
for Msun. I’m not actually sure that all those things are needed, but it changes to some symbol font, 9n is the sun symbol, then changes back to normal font.

8 kelle May 12, 2009 at 1:39 pm

@Melissa, that works for vector fonts, but not for postscript fonts. If postscript fonts are used, that produces a subscript greek nu symbol.

I think a reasonable solution for figures requiring a sun symbol is to just use vector fonts and the charthick keyword to make sure the text is legible at lower resolutions. Not the best solution, but it’s an option.

9 Marcos June 2, 2009 at 7:21 am

Hey, nice site- and look it’s updated unliked Macsingularity! What a concept.

My advice with IDL plots is … don’t use IDL. Unless it’s some sort of auto-churned out plot that needs to be updated constantly… but for papers I always used Grace, and the Mac program “Plot” (really needs a better name) isn’t bad either. Of course, constantly exporting and importing data is a pain so this only works when it’s time to make that one plot for the paper, but … I think it’s worth it rather than struggling with IDL.

10 David Fanning August 4, 2009 at 9:53 am

It’s possible you already have a True-Type font with the Sun Symbol already on your computer! Here is an article that describes several ways you can access and use it from within IDL.

I’m told the Apple Symbols font has a Sun Symbol that can be used to produce nice PostScript output.

Converting PostScript output to PNG output, for example, is trivial with ImageMagick’s convert command, and the resulting fonts look great in a Powerpoint presentation or slide. I write PostScript files and convert them to PNG files all in one go with PS_Start and PS_End, as described in this article:

This is really so easy, I don’t even think about it anymore from either a LINUX or Windows computer. I’m sure it would be just as easy on a Mac.

11 Kelle August 4, 2009 at 10:06 am

Yes, as suggested by the Coyote’s article on the Sun symbol, I did indeed try to install the Apple Symbols font in a mac installation of IDL and….I was completely unsuccessful. I think it can be done, but I was not able to work it out.

(wow, the Coyote commented on my post! I’m so honored!)

12 David Fanning August 4, 2009 at 11:10 am

Well, you are sending a lot of traffic to my site. I’m trying to figure out why.

When you say you were “unsuccessful”, did you get *anything*? Are you certain you had selected True-Type fonts (i.e., font=1)? Even with computers, there is usually a reason why things to wrong.

13 kelle August 5, 2009 at 3:26 pm

Here’s the page I was following:

Where I ran into a wall was converting the AppleSymbols.ttf file found on my system into a .pfb and or .afm file. I considered buying Astrology Pi One or Lucida Math Extension from Adobe ($26) but didn’t make it that far. I think this is probably the way to go… Reply 14 David Fanning August 6, 2009 at 7:00 pm Yikes! Yeah, I don’t think all that nonsense is necessary. I’ll see if I can borrow my son’s Mac before he leaves for college next week and figure out an easier method for you. Reply 15 David Ciardi August 25, 2009 at 10:15 am Kelle et al: (sorry about the long-ish post) I have struggled with this for quite a while and my solution partial solution was to use true type fonts (for now or thick hersey font). I tried copying the Apple Symbols.ttf into$IDL_DIR/resource/fonts/tt and adding an appropriate line to ttfont.map. However, the Apple ttf file appears to be in a form not readable by IDL. I get the following error when invoking the font (IDL> ; % PLOT: Unsupported glyph table format for TrueType fonts). However, I copied the Arial Unicode MS ttf from Windows and installed in IDL tt fonts directory and it worked perfectly. So the Apple tt font files seem to be in a format IDL can’t read, but Windows font files are ok (not a surprise since IDL can use the Windows font directory). This doesn’t solve the problem of having a postscript font with a sunsymbol … (Mac OS 10.5.8, IDL 7.0.4)

16 WayneS November 12, 2009 at 2:12 pm

Hi everyone, Why are you using the device hardware font rather than rendering a truetype font? Is the device font better for printing since the fonts are already in the printer? What about displaying these figures in talks as PDFs, does it really matter?

17 Kelle November 18, 2009 at 7:51 pm

@WayneS. I’m not a postscript expert, but the basic reason we use postscript fonts is because the ideal end result for a figure is to be included in a journal article as an EPS file. The best way to ensure an EPS figure looks the way you want it to is to use PS fonts. If you don’t use PS fonts, then you have to convert to outline or otherwise ensure the font is included in the EPS. This issue is touched on in the Graphics Guidelines for AAS Journals.

For talks, it really doesn’t matter if you use TT or PS as long as the characters are big and thick. But since you want to use PS for the paper, might as well use it all the time.

18 Jer November 27, 2009 at 12:36 am

I’ve gotten the sun symbol in TT fonts using the same method as David Ciardi, but only on my Mac. On my work desktop, I don’t have write access to the relevant directory. But… I can’t get kcorrect to work on my Mac, only on the Linux desktop. So I can either do the calculation but not plot it nicely, or plot it nicely but not have anything to plot!

Anyone know a way to have user-space TT fonts in IDL? (or get kcorrect to compile on Leopard?)

19 Jaesub December 12, 2009 at 2:10 am

hmm, I wonder this was mentioned (too lazy to read all the text and comments, if so, forgive me), but there is a simple solution to make
the idl default font very readable in ps plots. It’s

!p.charthick=3

which is similar to

!x.thick=3
!y.thick=3
!z.thick=3

for drawing lines, etc.
A quick solution for a lazy person.

20 Tigran February 14, 2010 at 3:13 am

Sorry to barge on you with my solution to the problem but some Mac people may find this useful. Previously I used to straggle with fonts and all the plotting particulars in IDL but then I’ve decided to go simpler: I use IDL to produce the plot or the image then I get this result into keynote and do all the annotations and graphics. Here I can use all the possible fonts available in the system. Next I export it as a PDF and it’s done. I could also print it to PDF using Adobe distiller if the file size is the issue. Of course I can crop and do some final tuning in the end with just Preview. I know this is somehow cheating but it’s simple and quick.

21 Kelle January 4, 2011 at 9:27 am

check out a post by Saurav on adding symbols to IDL figures with LaTeX and PSFrag:
http://www.astrobetter.com/idl-psfrag/

22 Jim Davenport November 6, 2012 at 12:33 am

Well this reply is very far after the original post, but perhaps it will be of some use to others. I still use the IDL Vector fonts because they offer a wide range of symbols. To make figures more readable, I use the following commands:

!p.thick=2
!x.thick=2
!y.thick=2
!p.charthick=2.5
!p.font=-1
!p.charsize=1.6

I also recommend using the cubehelix color scheme:
http://www.mrao.cam.ac.uk/~dag/CUBEHELIX/

I always use encapsulated postscripts.

Finally (though I could go on at great length…) I use this handy chart to rapidly find/remember symbols in the Vector Font set [apologies, I can't remember where this figure is from. I did NOT make it]

23 David Fanning November 6, 2012 at 8:30 am

Just a note and follow-up to Jim’s post. The PS_Start routine, which is what I use to set up all my PostScript output, sets the system variables Jim mentions to 3 (rather than 2), since I think this, too, gives much better PostScript output. More importantly, it gives much better raster output when it is converted from PostScript. This is how all the Coyote Graphics routines produce PostScript and raster output automatically. Also, I really like Jim’s CubeHelix color table, so I have added it to cgLoadCT and XColors this morning.

24 glanplon January 6, 2014 at 8:30 pm

Hi
When I use set_plot ‘ps’ and use the cgimage i get the error

CGIMAGE: An AlphaBackgroundImage is required to create transparent images in PostScript.
Any help
glanplon