Plotting with iPlot
The IDL iPlot tool displays your data in plot form. The iPlot tool then allows you great flexibility in manipulating and visualizing plot data. iPlot can be used for any type of two- or three-dimensional plot, including scatter plots, line plots, polar plots, and histogram plots.
Creating a Simple 2-D Plot
To create a simple line plot in the iPlot tool, enter the following code at the IDL command line:
In this case, we are using the RANDOMU function to return twenty uniformly-distributed, floating-point, pseudo-random numbers that are greater than 0, and less than 1.0.
Creating a 2-D Overplot
In the iPlot tool, you may plot a new data set over a previously-drawn data set. This process (called overplotting) is useful for directly comparing multiple data sets.
In this example, we will plot a cosine wave on top of a sine wave.
- The variable
theorystores the points of a sine wave of decreasing amplitude. - Plot the sine wave in the iPlot tool.
- Create the variable
newtheoryto contain cosine wave points. - Overplot the cosine data in the iPlot tool.

theory = SIN(2.0*FINDGEN(200)*!PI/25.0)*EXP(-0.02*FINDGEN(200))
newtheory=COS(2.0*FINDGEN(200)*!PI/25.0)*EXP(-0.02*FINDGEN(200))
IPLOT, newtheory, /OVERPLOT, $
LINESTYLE=2
This plots the second line in the same iPlot window as the first. The LINESTYLE keyword changes the line style property of the plot to display a dashed line rather than a solid line. You can also overplot in the iPlot tool simply by loading new data over an older data set.
Plotting an ASCII Data Set
In this example, we will import an ASCII data set into IDL and plot it with the iPlot tool. Enter the following code at the IDL command line:
- Create an ASCII template, which defines the format of a particular ASCII file. IDL will use this template to import the data. The
plotTemplatevariable contains the template. - A dialog appears, prompting you to select a file. Select the
plot.txtfile in theexamples/datasubdirectory of the IDL distribution. - Select the Delimited field type, since the ASCII data is delimited by tabs (or spaces).
- In the Data Starts at Line box, enter a value of 3. (The data does not start at line 1 because there are two comment lines at the beginning of the file.)
- Click Next.
- In the Delimiter Between Data Elements section, select Tab.
- Click Next.
- Name the ASCII file fields by selecting a row in the table at the top of the dialog and entering a value in the Name box.
- Click Finish.
- Enter the following code at the IDL command line to import the ASCII data file
plot.txtusing the custom templateplotTemplate. - Plot the
temperature1vs.timedata.

plotTemplate = ASCII_TEMPLATE( )
After selecting the file, the ASCII Template dialog appears.
For more information on importing ASCII data, see Reading ASCII Data.
Adding Plot Titles
The iPlot tool allows you to modify your plots by adding elements such as error bars, legends, and axis titles. You can also manipulate the plot with tools such as curve fitting or filtering.
In this example, we will add a main title and axis titles to the ASCII data plot we created previously. The VIEW_TITLE keyword adds a main title, and the XTITLE and YTITLE keywords add axis labels. If you have not already done so this session, do the example Plotting an ASCII Data Set.
Enter the following code at the IDL command line, which will create a new iPlot dialog and add titles to the plot.
Alternately, you could add title annotations to an existing plot by selecting the Text tool
, positioning the cursor at the location where you want the title to appear, and typing the text. Double-clicking on the text displays the text annotation property sheet, which allows you to modify the size, font, color, and other properties of the annotation.
Changing the Data Range of a Plot
Your data set may contain more data than you want to display in a particular plot. While you could use IDL's array subscripting syntax to create a subset of the original array, it is often easier to simply limit the range used when creating the plot display.
For example, suppose you wanted to restrict the range displayed in your plot to show only time values (the X-axis) between 15 and 18 seconds, and temperature values (the Y-axis) between 8 and 13 degrees. Using the [XYZ]RANGE keywords to the IPLOT routine allows you to do this when creating the plot:
IPLOT, plotAscii.time, plotAscii.temperature1, $
XRANGE=[15,18], YRANGE=[8,13]
Alternately, you could start by displaying the full data range in iPlot, and then alter the Dataspace properties to reflect the new X and Y ranges:

Using Plotting Symbols and Line Styles
When plotting several data sets in a single plot, it is often useful to use symbols, line styles, and legends to differentiate between the data sets. The following procedure created the plot shown at right.
- First, plot the
temperature1values using the standard (solid) line style and a diamond symbol to mark the data points: - Next, overplot the
temperature2values using a dashed line (LINESTYLE=2) and a triangle symbol to mark the data points (SYM_INDEX=5): - To insert a legend, click in the plot area to select it (the axis lines around the plots will be highlighted), then select New Legend from the Insert menu. The legend is created using default names for the data sets (
PlotandPlot1). - Double click on
Plotin the legend to bring up the property sheet, and change the value in the Text field toTemperature 1. Similarly, changePlot1toTemperature 2.
IPLOT, plotAscii.time, plotAscii.temperature1, SYM_INDEX=4
Note that we set the SYM_INDEX keyword equal to four to create the diamond symbols.
IPLOT, plotAscii.time, plotAscii.temperature2, SYM_INDEX=5, $
LINESTYLE=2, /OVERPLOT
Adding Error Bars
You can add error bars to your plot using the [XYZ]ERROR keyword to IPLOT.
Suppose you know that the temperature values you have collected are only accurate within 0.3 degrees Celsius. To include error bars on your plot of temperature versus time, you would do the following:
- Create an array with the same number of elements as you have temperature readings:
- Use the YERROR keyword to add the error bars:
error_bars = FLTARR(N_ELEMENTS(plotAscii.temperature1))+0.3
This creates a floating-point array with the same number of elements as the plotASCII.temperature1 array, setting each element's value equal to 0.3.
Note
The size of the error bar does not need to be the same for every data point. Each element in the error_bars array could contain a different value.
IPLOT, plotAscii.time, plotAscii.temperature1, YERROR=error_bars





