Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 803
News FAQ
Search Home


next up previous contents
Next: Example: Using the PGPLOT primitives Up: Plotting Previous: Interacting with the PGplotter

Example: Reading Data from an ASCII Table and Making Plots

Suppose you have a file named SampleData.txt which contains the following data:

0.1  0.248   1.355
0.2  0.596   1.306
0.3  0.634   1.569
0.4  0.877   1.312
0.5  0.874   0.871
0.6  1.182   0.550
0.7  1.088   0.390
0.8  1.169   0.261
0.9  1.157   0.086
1.0  1.075   0.171
1.1  0.935   0.250
1.2  0.798   0.411
1.3  0.805   0.449
1.4  0.504   0.530
1.5  0.307   0.552
1.6 -0.035   1.004
1.7 -0.172   1.317
1.8 -0.232   1.648
1.9 -0.488   1.567
2.0 -0.440   1.291

Then the data can be read and plotted using the following script:

include 'table.g'
include 'pgplotter.g'
#
t := tablefromascii('sample.tbl','SampleData.txt',,T) 
t.colnames() 
#<< Column1 Column2 Column3
x  := t.getcol('Column1')
y1 := t.getcol('Column2')
y2 := t.getcol('Column3')
pg := pgplotter()
pg.plotxy1(x,y1)
pg.plotxy1(x,y2)
#
t.done()                     # Destroy tools when finished
pg.done()

The tablefromascii command (actually a constructor that constructs a Table tool called t) serves to convert the ASCII data into an AIPS++ table, which is written to disk under the name sample.tbl. The disk table can subsequently be reaccessed by connecting it to a Table tool via the constructor t := table('sample').

The next Glish statement in the example is useful during interactive sessions to list the names of the columns in the table. In this case, table t has columns named Column1, Column2, and Column 3 (the output is not shown in the example script), which are the default names given by tablefromascii when no header information is provided with the ASCII table.

The first column of the ASCII file is interpreted as the abcissa (and stored in the Glish variable x) and the numbers in the next two columns are plotted against it.

Both columns from the ASCII table are plotted on a single set of X-Y axes. The function plotxy1 can be called repeatedly to add new lines on top of the existing plot, and the scaling of the axes will be adjusted accordingly.

To plot data on the same plot but using an alternate scaling on the X-Y axes, the function plotxy2 can be used. For example, the following lines can be appended to the example to plot new data without altering the original X- and Y-scales.

xnew := 1000:2000
ynew := 100*sin((xnew-1000)/100)
pg.plotxy2(xnew,ynew)

\begin{figure}\begin{center}
\epsfig{file=cookbook.dir/plotfig1.ps,width=6.0in}
\end{center}\end{figure}

Several high level PGplotter calls, including plotxy, plotxy1, plotxy2, timey, and timey2 are intended to provide a way to take a quick look at a user's data. The functions plotxy1 and plotxy2 are intended to be used together and may not mix smoothly with plotxy or primitive PGPLOT calls in all cases. Similarly, timey and timey2 are meant to work together. When a sophisticated plot is required, it may be necessary to stick to the primitive function calls.


next up previous contents
Next: Example: Using the PGPLOT primitives Up: Plotting Previous: Interacting with the PGplotter   Contents
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2004-08-28