Line Plots
You can create line plots using the PLOT and IPLOT procedures. Keywords to these routines allow you to add titles, change the range and type of axes used, and customize your plots in other ways. This section describes:
Creating Line Plots with PLOT
Each call to PLOT establishes the plot window (the rectangular area enclosed by the axis), the plot region (the box enclosing the plot window and its annotation), the axis types (linear or logarithmic), and the scaling. Data variables are then plotted within the plot window.
First, plot a simple graph using a sine function. Use the FINDGEN function to create a 100-element vector of floating-point integers, and multiply that vector by 2π/100. Then use the PLOT procedure to create an X-Y plot.
- Use the FINDGEN function to create a 100-element vector of floating-point integers, and multiply that vector by 2π/100. The vector X will contains your data values.
- Now, use PLOT to plot the sine of the X values versus their vector subscript values.
- Finally, use the OPLOT procedure to overplot the cosine of the X values in light blue.
OPLOT, COS(X), COLOR='FFCC66'x
Note
The color value for the plot line is specified using a scalar value — in this case a hexidecimal number specifying a color triple. If your system uses an indexed color display rather than a TrueColor display, you would use a single integer to specify a color index rather than supplying a color triple.

Creating Line Plots with IPLOT
The IPLOT procedure uses the IDL iTools framework to display plots in an interactive window rather than as a static display. To replicate the above example using IPLOT:
X = 2*!PI/100 * FINDGEN(100)
IPLOT, SIN(X)
IPLOT, COS(X), /OVERPLOT, COLOR=[102,204,255]
Note
When using IPLOT we specify the color value using a three-element RGB triple rather than a scalar hexidecimal value. This is true on both indexed and TrueColor displays.

The iTools interface allows you to modify the appearance of your plots by changing colors, changing line styles, adding annotations, etc. See Working with Plots and Introducing the iTools in the iTool User's Guide for additional details.
Adding Titles
You can easily add titles to your plots. For this example, we will use some data from IDL's examples/data directory. First, restore the plot_data.sav file, creating a structure variable named plot_data:
RESTORE, FILEPATH('plot_data.sav', SUBDIR=['examples', 'data'])
The plot_data structure variable contains three data variables in the fields Time, Temp1, and Temp2. We will plot the Temp1 data variable versus the Time data variable, adding a title at the top and titles for the X and Y axes:

Tip
To create the same annotations in IPLOT, substitute the VIEW_TITLE keyword for the TITLE keyword in the above command.
Changing the Axis Range
Unless you specify otherwise, IDL selects an appropriate axis range based on the data values you provide to the plotting routines. To specify a different axis range, use the XRANGE and YRANGE keywords. For example, to select the data collected between the 13th and 18th seconds in the above example, set the XRANGE as follows:

Logarithmic Axes
By default, IDL's plotting routines use linear axis scales. To use a logarithmic axis scale instead, specify the XLOG or YLOG keyword.
Note
When using logarithmic axes, you must ensure that the axis range does not include zero. Use the XRANGE or YRANGE keyword to specify a safe axis range.
PLOT, FINDGEN(100), XRANGE=[0.1, 100], /XLOG

Using Plotting Symbols
When plotting multiple datasets within the same plot, it is often useful to distinguish the plot lines using different symbols. For example, suppose you wish to plot some data values collected in the field along with a curve fitted to the collected data points. You might use an asterisk to denote the real-life data and a solid line to denote the theoretical curve that fits the collected points:
See the description of the PSYM graphics keyword for details on using plotting symbols.
Further Information
For additional information on plotting, see
- PLOT in the IDL Reference Guide
- IPLOT in the IDL Reference Guide
- OPLOT in the IDL Reference Guide
- Working with Plots in the iTool User's Guide