Previous Getting Started with IDL: 2-D Plots Next

Plotting with Data Sets

To demonstrate IDL's capability to read a data set and plot it, we will create and use and ASCII template.

  1. At the IDL command line, enter the following to create the variable plotTemplate, which will contain your custom ASCII template:
  2. plotTemplate = ASCII_TEMPLATE( )  
    

     

    A dialog box appears, prompting you to select a file.

     

  3. Select the plot.txt file in the examples/data subdirectory of the IDL distribution.
  4.  


    Note
    Another way to import ASCII data is to use the Import ASCII File toolbar button on the IDLDE toolbar. To use this feature, simply click the button and select plot.txt from the file selection dialog.

     

  5. After selecting the file, the Define Data Type/Range dialog appears. First, choose the field type. Since the data file is delimited by tabs (or whitespace) select the Delimited button. In the Data Starts at Line field, specify to begin reading the data at line 3, not line 1, since there are two comment lines at the beginning of the file. Click Next to continue.
  6.  

  7. In the Define Delimiter/Fields dialog box, select Tab as the delimiter between data elements since it is known that tabs were used in the original file. Click Next.
  8.  

  9. In the Field Specification dialog box, name each field as follows:
    • Click on the first row (row 1). In the Name field, enter time.
    •  

    • Select the second row and enter temperature1.
    •  

    • Select the third row and enter temperature2.

     

  10. Click Finish.
  11.  

  12. Type the following line at the IDL command line to read in the plot.txt file using the custom template, plotTemplate:
  13. PLOT_ASCII = READ_ASCII(FILEPATH('plot.txt', SUBDIRECTORY= $
       ['examples', 'data']), TEMPLATE=plotTemplate)  
    

     

  14. Plot the first set of data on temperatures which is stored in Temp1:
  15. PLOT, PLOT_ASCII.TIME, PLOT_ASCII.temperature1  
    

     

    Figure 4-6: Plotting an existing data set using PLOT

    Figure 4-6: Plotting an existing data set using PLOT


Note
The file is read into a structure variable. For more information on accessing ASCII data, see Reading ASCII Data.

  IDL Online Help (March 06, 2007)