Making Fonts Better in IDL Postscript Output

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.

Make the figure close to the actual printed size

Bad

BAD: 18 cm across and vector font

Better

BETTER: 9 cm across and Postscript font

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 fontvect

fontdev

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.

27 comments… add one
  • Trent Apr 28, 2009 @ 0:52

    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.

  • Tanya Apr 28, 2009 @ 11:00

    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

  • Marshall Apr 29, 2009 @ 13:42

    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.

  • kelle Apr 30, 2009 @ 9:33

    @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

  • Andrew May 5, 2009 @ 10:07

    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

  • kelle May 5, 2009 @ 10:18

    @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.

  • Melissa May 12, 2009 @ 13:01

    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.

  • kelle May 12, 2009 @ 13:39

    @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.

  • Marcos Jun 2, 2009 @ 7:21

    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.

  • David Fanning Aug 4, 2009 @ 9:53

    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.

    http://www.dfanning.com/misc_tips/sun_symbol.html

    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:

    http://www.dfanning.com/graphics_tips/weboutput.html

    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.

  • Kelle Aug 4, 2009 @ 10:06

    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!)

  • David Fanning Aug 4, 2009 @ 11:10

    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. 😉

  • kelle Aug 5, 2009 @ 15:26

    Here’s the page I was following:
    Adding Your Own PostScript Fonts

    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…

  • David Fanning Aug 6, 2009 @ 19:00

    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. 🙂

  • David Ciardi Aug 25, 2009 @ 10:15

    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)

  • WayneS Nov 12, 2009 @ 14:12

    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?

  • Kelle Nov 18, 2009 @ 19:51

    @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.

  • Jer Nov 27, 2009 @ 0:36

    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?)

  • Jaesub Dec 12, 2009 @ 2:10

    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.

  • Tigran Feb 14, 2010 @ 3:13

    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.

  • Kelle Jan 4, 2011 @ 9:27

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

  • Jim Davenport Nov 6, 2012 @ 0:33

    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/
    http://www.astro.washington.edu/users/jrad/cubehelix.pro

    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]
    http://www.astro.washington.edu/users/jrad/vector_fonts.png

  • David Fanning Nov 6, 2012 @ 8:30

    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.

  • glanplon Jan 6, 2014 @ 20:30

    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

  • AlexS Oct 30, 2014 @ 17:44

    I know this is way late, but regarding the sun symbol, if you really needed it in your plot why not just get a nice jpeg of a sun symbol and just manually insert it into your plot using read_jpg and tvscl, or something like that?

  • JoeK Jun 8, 2015 @ 11:38

    How do I call the CubeHelix colour table properly using cgloadCT, specifying a number of colour steps? The following produces a greyscale plot when using cgcontour:

    cgloadCT, cubehelix, /reverse, ncolors = nlevels+1, bottom=0

    Any help would be great!

  • Christina Jun 6, 2016 @ 13:41

    I know this comment is on a WAY outdated post, but I hope someone is still listening out there.

    It’s true that using !p.font=1 to scale produces more clear text in a plot (and you can choose your font, and bold also), but one thing I have not seen addressed here is how bad other linestyles look on these plots. Anything other than solid produces line pieces that are extremely far apart compared to what they might look like when produced at a larger size and scaled down. Does anyone have some tips for how to fix this problem?

Leave a Reply

Your email address will not be published. Required fields are marked *