Making a multi-panel plot

Multiple-panel plots (or small multiples, from Edward Tufte) group a set of plots for convenient comparison. In DG, multi-panel plots can be built with the !p.multi system variable, or the MULTIPLOT astrolib routine. I’d like to show how to make a multi-panel plot in NG.

I coded up an example that creates a set of plots similar to those on the NCAR Foothills Lab weather station page, using an archive file from yesterday (Oct 17), when we had a windstorm in Boulder. Here’s the result:

A six-panel plot of measurements from the NCAR FL weather station.

You can download the example program and its associated data from here. If I could run a lowpass filter over my code, here’s the fundamental structure that would emerge:

p1 = plot(data1, layout=[2,3,1])
p2 = plot(data2, layout=[2,3,2], /current)
p3 = plot(data3, layout=[2,3,3], /current)
p4 = plot(data4, layout=[2,3,4], /current)
p5 = plot(data5, layout=[2,3,5], /current)
p6 = plot(data6, layout=[2,3,6], /current)

Six plots, six calls to PLOT. LAYOUT uses a three-element array, [ncolumns, nrows, plot index], where plot index is one-based, to organize a multi-panel plot. The CURRENT keyword is needed on plots after the first so that PLOT knows to place the plot into the current window.

For the details (the highpass filter!) of making the plot above, please see my example program.

About these ads

About Mark

I solve scientific programming and visualization problems with IDL.
This entry was posted in language, visualization and tagged , , , , , . Bookmark the permalink.

6 Responses to Making a multi-panel plot

  1. David Fanning says:

    Is that zip file password protected? I can’t seem to open it with two different types of extraction software on my Windows machine.

  2. Paul says:

    I like to use the “position=position” keyword, and then I can also use the x and y indices for placing titles and labels. I’ll quickly describe what I do below, in case it’s useful too:

    The link below points to my plot_position.pro script, which I use to calculate the “position” vector for an arbitrary ncol by nrow page. You can return the position vector for a given plot “cnt”. It also controls the distance between plots (with the *buffer keywords), so you can gang plots together if you wish. You can also (e.g.) produce a top row plot which spans the full page, with a second row plot with three columns underneath – just use the pageTop keyword on the second call. An example is below (caveat emptor: untested as I’m still waiting for new license key!):

    ;; Get position for wide plot
    winDim = [600,300]
    ncol = 1
    nrow = 2
    leftMargin = 0.1 ;; space for y and x titles
    botMargin = leftMargin
    buffer = 0.05

    cnt = 1
    topPlotPosition = plot_position(ncol,nrow,1,leftMargin,botMargin,buffer,$ ;; 1 col, 2 rows
    winDim=winDim, /newWin) ;; draw new window on first call

    ;; Now get position of second row plots, using y0 of topPlotPosition as the top of the page
    ncol = 3
    nrow = 1
    cnt = 1
    botPlotPosition1 = plot_position(ncol,nrow,cnt,leftMargin,botMargin,buffer,pageTop=topPlotPosition[1]-buffer)
    botPlotPosition2 = plot_position(ncol,nrow,cnt+1,leftMargin,botMargin,buffer,pageTop=topPlotPosition[1]-buffer)
    botPlotPosition3 = plot_position(ncol,nrow,cnt+2,leftMargin,botMargin,buffer,pageTop=topPlotPosition[1]-buffer)

    !null = plot(fingen(10),findgen(10),position=topPlotposition

    (Can obviously do this in a loop to make it neater)

    I guess it would be better if everything except ncol, nrow and cnt had defaults – planning to do that once I have time to edit the scripts that call it! …Hope it’s useful for some.

    http://sites.google.com/site/pauljyoung/plot_position.pro

  3. Pingback: Positioning plots | The IDL Data Point

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s