Weeks lab advice for making figures in IDL

written by Eric.

Lab Home -- People -- Experimental facilities -- Publications -- Experimental pictures -- Links

Introduction

We frequently make figures and often need to make nice figures. Usually this starts with making figures for a presentation, and eventually we make figures for a publication -- often starting with a previous version of the figure make for a presentation. You are welcome to use any program you like to make your figures. That being said, if you want to use IDL to make your high-quality figures, this page will explain how to do so. Advantages of using IDL:

Disadvantages of using IDL:


The script

IDL lets you execute commands in a textfile using the @ symbol:
IDL> @mkfigure
So you're going to put your plotting commands into a file and when you want to make your graph, you execute that file at the command line. A while ago I wrote a basic script that does lots of useful things: Here's my version of the rainbow:

Just imagine how nice your graphs will look using colors from this palette!

mkfigure -- download the script here. Or, on any of our lab Linux computers, the script is located at /data/eric/mkfigure.sh . The letters "mk" stand for "make."

How to use:

  1. Copy the script to the directory where you want your figure to be made.
  2. Rename the script, usually with a name related to the figure you want to make, like "mkmsd" or "mktrajectories".
  3. Edit the first line of the script to provide a filename for your figure, for example "msd" or "trajectories".
  4. Put your plot commands between the lines marked "BEGIN PLOTTING BELOW" and "END PLOTTING ABOVE". Often you start by putting plotting commands you were already doing in IDL to make a simpler version of the graph.
  5. Try running your script. It will display an image of your figure. As needed, look at the last two lines of the script. One line displays a fullsize image of your figure, the other halfsize. Uncomment the one you desire. In other words, if your figure ends up looking too big on the screen, just uncomment the smaller version. And vice versa.
  6. Do not otherwise edit the lines at the top or bottom of the script unless you know what you're doing.
  7. One possible exception: the line with the linux command "pstopnm" sets the resolution of your JPG file, so as described in a comment in the 'mkfigure' file, you can change this line to increase your resolution. (Or decrease it, although I'm not sure why you'd want to do that.)

Helper files

The script calls two linux scripts, one IDL program, and loads in a saved color table. And additionally often when making figures I use 'ktex2idl' to get the math symbols correct, so I'm including that. On the lab linux computers, bbox_add.pl and pagebbox.sh are located in ~weeks/bin/ ; ericcol.tbl is located in ~weeks/ ; and cropjpg.pro is in the standard IDL code repository. The 'mkfigure' script automatically calls these files from the correct locations. So if you're on our lab linux


Setup file

My preferred method is to have a separate IDL script called "setup" that reads in data for the figure(s) I want to make. The concept is that reading in files causes wear & tear on the hard drive, and also takes time. So just read in these files once. Perhaps also, do any pre-processing of the files, especially if it's time intensive. And then the plotting is put into the "mkfigure" script, that is, the plotting of the data you read in and/or processed in "setup".

This is especially useful when you are making a series of minor changes to the "mkfigure" file to make your figures look amazing. You don't want to keep reading in the data every single time. That's really the reason I keep "setup" and "mkfigure" as separate files. Often for a given project (or paper) I will have just one "setup" file in the directory containing the data for that project, and that file will read in data for any and all figures I'm making. Then I'll have separate files starting with "mk" that make the various figures related to that project.


Examples

Introduction

If you're on a lab linux computer, all of these can be found in /data/eric/figures/ . Go there and try running the scripts as suggested below! Otherwise, you can download the setup & mkfigure files, along with the necessary data, in examples.zip.

This is Fig. 3 from Tapia-Ignacio et al., PRE 102, 022902 (2020). On the lab Linux computers, you can make this with

IDL> @setup01
IDL> @mkfig01

Comments:

  • The script uses the graphics keyword POSITION to draw the three graphs at different locations on the screen. After the first graph is drawn, the second and third graphs also use the graphics keyword /NOERASE to avoid clearing the screen.
  • With POSITION you have to specify the lower-left corner and the upper-right corner of the graph. These specifications have to be between 0 and 1, that is, you're giving coordinates relative to the screen where (1,1) is the upper right hand corner of what's possible to plot. My usual trick for multi-panel graphs is to define some variables to make this easier. For this three panel graph, I have:

    x1 = 0.10 & x2 = 0.35
    y1 = 0.05 & dy = 0.20
    y2 = y1 + dy + 0.02
    y3 = y2 + dy + 0.02
    

    Panel (a) is then POSITION=[x1,y3,x2,y3+dy] and (c) is POSITION=[x1,y1,x2,y1+dy]. The advantage of this is that if I want to make the graphs slightly wider or narrower, I just change x2 near the top of the plotting commands. To make all the graphs slightly taller, I increase 'dy'. Changing the space between the graphs would be changing the '0.02' in the last two lines. If I decided I needed a fourth panel, it would be straightfoward to add in a 'y4' and reduce 'dy' and maybe 'x2' to make the graphs all a bit smaller.
  • Likewise each graph is made using CHARSIZE=cs where the variable 'cs' is set near the top of the script, so I can adjust the font size of all three panels simultaneously. In this script I also use the same CHARSIZE for the (a) (b) (c) labels, although for some figures I want those to be a different size so I might use a variable 'cs2' for that size.
  • The IDL command XYOUTS is used to label the curves with their alpha values in panel (a), and also used to add the panel labels (a) (b) (c).
  • In panel (c), I use a small for-loop to add the error bars by drawing horizontal and vertical lines at the appropriate places.
  • I use Ken Desmond's program "ktex2idl.pro" to label the axes -- in other words, to get subscripts and superscripts, math symbols like alpha, etc.
  • In panel (c) I use YRANGE=[2,20] and /YSTYLE to force the vertical axis to be between 2 and 20, rather than letting IDL go with its preference of 1 to 100.
  • This figure uses advice I got from Harry Swinney: the two most opposite symbols (and thus easiest to distinguish) are circles and triangles.


This is Fig. 4 from Tapia-Ignacio et al., PRE 102, 022902 (2020). On the lab Linux computers, you can make this with

IDL> @setup02
IDL> @mkfig02

Comments:

  • The dashed lines are labeled with XYOUTS using the ORIENT keyword to rotate the text. For example:

    xyouts,0.03,1.0,orient=45,ktex2idl('\sim$\Delta{}t$^{1.7}'),chars=cs,/data
    

  • Here I'm making full use of the rainbow color palette.
  • This graph is just one panel so I did not use POSITION to try to resize it.


This is Fig. 4 from Weeks & Weitz, PRL 89, 095704 (2002). On the lab Linux computers, you can make this with

IDL> @setup03
IDL> @mkfig03

Comments:

  • This is old school, just black & white!
  • It's also old school in that it predates "ktex2idl", so the math symbols are done using IDL's built-in font-changing commands. For example, the vertical axis of panel (a) is labled "!8P!7(!9q,f!7)" which is ancient IDL code for P(theta,phi). I don't recommend this anymore.
  • Nonetheless, this nicely demonstrates using pi as a symbol when labeling axes related to angles in radians.
  • And I like the inset a lot. It is placed using the graphics keyword POSITION.
  • The arrows are drawn with the ARROWS IDL command.
  • There are several ways I could have made the main graph in panel (b). Simplest would be rescale the data and use oplot. For whatever reason, in 'mkfig03' I just plot the data twice in the same location. (Probably in some earlier version of this mkfig file, the sigma data and g(r) data were in different panels.)


This is Fig. 7 from Weeks & Criddle, PRE 102, 062153 (2020). On the lab Linux computers, you can make this with

IDL> @setup04
IDL> @mkfig04

Comments:

  • This example makes it clear that your graphs can have any aspect ratio you might want. In terms of the POSITION graphics keyword, each graph has a width of 0.6 and a height of 0.2.
  • I like how panels the panels are labeled "(a) epsilon = 0.3" so that the reader immediately knows the epsilon value without having to consult the caption.
  • In hindsight, a missed opportunity: I should have made the middle panel purple and the bottom blue (as the bottom panel is the "coldest" behavior).


Extra tips


For more information, please contact Eric Weeks <weeks(at)physics.emory.edu>