Using IDL for more advanced Plotting


Table of Contents

Introduction
A brief introduction, with links to other valuable IDL sites.
Getting started
A few basic hints that will help you get started with the command line interface and a link that will help you get idl running on your display.
Create Plots with Color lines and Legends
This uses some user-written routines.
Create Plots with a Second Axis on the Right
This uses standard IDL calls.
Simple MDS Access
Read MDS signals into your IDL code with a few simple calls.
An MDS Plotter Widget
A simple point-and-click program that you can customize for yourself, or use as is. Allows selecting local printers and sending graphics to them.
Plot Stacks of MDSplus Signals
A slightly more elaborate point-and-click program for viewing a series of plots from MDSplus.
Combined Surface Plotting
Some basic, and some fancy ways of plotting 2-D data.
Other IDL Topics
How to find out more about IDL.


Introduction

This is a second tutorial on using IDL, at PPPL. If you have not used IDL for more than a few hours, you should work through the examples in the IDL Introduction

This tutorial is organized as a set of examples with limited explanation. The most effective way for you to go through this tutorial is by running IDL in a separate window, and trying out the commands and programs as you read the tutorial. For maximum benefit, you should save copies of the programs in a personal directory, and experiment with changing them.


Getting started

You need to know about How to Setup IDL at PPPL. This will tell you on which machines IDL is running, how to set up your environment, how to set your display, and how to find documentation.

Recall that IDL programs can be stopped using control-C. (Hold down the control key and hit the letter c). IDL can be aborted immediately using control-\. (All variables are lost and the state of open files will be uncertain).


Create Plots with Color lines and Legends

This simple program shows you how to go beyond the one-plot-per-page method.
pro demolegend

; demolegend.pro
;
; this file demonstrates the use of the Legend routine in multiplots

!p.multi=[0,1,2]

meanings = ['good stuff', 'better stuff', 'best stuff']
psyms = [-1,-2,-4]
colors = [MK_COLOR('red'),MK_COLOR('yellow'),MK_COLOR('blue')]
lines = [1,2,4]

x=FINDGEN(11)

FOR nplots=0,1 DO BEGIN

        PLOT,x,x^1.3,/nodata
        for i=0,2 do OPLOT, x, x^(1.1+(i/10.)), psym=psyms[i],   $
                color=colors[i], linestyle=lines[i]
        LEGEND, meanings, /right, /top, psym=psyms,  $
                color=colors, linestyle=lines
ENDFOR
!p.multi=[0,1,1]

return
end
Type the following at the IDL prompt

    IDL> demolegend
This will execute the commands above (if the directory containing demolegend is in your IDL "path".)

As an excersize, try modifying the above code to place the legend on the left instead of on the right (use the /left keyword in the LEGEND call, rather than /right).

To examine the source of any user-written routines used in these examples, locate it with doc_library. If the author followed the IDL convention for documenting the source, you will also see that displayed. For example, to find out where mk_color.pro is located, type:

	IDL> doc_library,'mk_color'
(If you are at PPPL, or do not wish to use the locally-written routines, like
mk_color, see http://NSTX.pppl.gov/nstx/Software/IDL/simplecolors.html for an easy way to plot with named colors in IDL.)


Create Plots with a Second Axis on Right

; plot_right.pro - plot with axis on right

x=findgen(100)
y=0.95*sin(x/5)

!x.margin=[8, 9]
   ; plot with no right axis
plot,x,y, ystyle=8, ytitle='_____ Sine Wave'

newx = findgen(500)/5.
newy = 1000.*SIN(newx/7 + 1)*exp(-1.*  newx/100)

PLOT, newx,newy, /noerase, xrange=!x.crange, line=2, ystyle=4, xstyle=1

   ; make an axis on the right for the last plot
AXIS, YAXIS=1, YRANGE=!y.crange, ytitle='----- Damped Wave'
Type the following at the IDL prompt

    IDL> @plot_right
You should see something this:


Simple MDS Access


    (put this in your .cshrc or .bashrc file: 
       module load nstx  )
                                   
    MDSOPEN, 'wf', 130000
    signal = '\ip'
    f = MDSVALUE( signal )
    time = MDSUNITS( signal, /TIME )
    flabel = MDSUNITS( signal, /UNITS )
    timelabel = MDSUNITS( signal, /TIME, /UNITS )

    PLOT, time, f/1000., XTITLE = timelabel, YTITLE = 'milli'+flabel
For more examples of MDSplus access at PPPL, see
http://NSTX.pppl.gov/nstx/Software/IDL/mdsaccess.html.


An MDS Plotter Widget

If your are running x-windows, type the following at the IDL prompt:

    IDL> mdsw

Some of the above "widgets" are buttons that you click on to initiate actions (like making a plot or sending the plot to the printer), others are fields you can type in (like signal) and the field containg the small rectangle on the right is a pull-down menu. You can rescale the plot by placing the mouse pointer over the plot, holding down the middle mouse button, dragging, and releasing. The x- and y-positions of the cross-hairs are shown in the small boxes at the bottom of the plot.

To find where this source for mdsw.pro is located on your computer, type:

	IDL> doc_library,'mdsw'
You should probably look at
mdsw_noch.pro. It is simpler and illustrates most of the important concepts.

If you want to customize your own MDSplus plotting widget, the easiest way may be to copy all the routines from $NSTXUSR/util/misc/plotw on the PPPL Unix cluster, and adapt the "include" files to your purposes.


Plot Stacks of MDSplus Signals

This is a more elaborate MDSplus plotting widget that you can customize. If you have a list of MDSplus signal names in a file named mdsplussig.txt in the directory from which you are running IDL, they will be plotted when you click on "My Signals." Look at the code for stackplot.pro on the PPPL Unix Cluster


Combined Surface Plotting

Type the following at the IDL prompt

    IDL> vectorsurf
This will execute the commands in the file
vectorsurf.pro.

Some aspects of this routine are fairly complicated, but may be useful as it stands.


How to find out more about IDL.

There is an excellent demo supplied with idl, which shows many of the advanced things IDL can do. Just type "demo" at the IDL prompt.

You may also want to look at the IDL supplied examples in /usr/local/rsi/idl/examples on Linux.

You should also visit these valuable IDL sites, especially the ones that let you search for IDL routines written by others (no such search exists for fusion, or PPPL-specific software, but it should -- some locally-written routines are described at http://nstx.pppl.gov/nstx/Software/Programming/idl_routines.html).


Return to the NSTX Software Page

http://nstx.pppl.gov/nstx/Software/IDL/idl_class2.html
Edited for NSTX: 22-Sep-2009
by: Bill Davis