What is xgr?
xgr is a simple program to display one-dimensional numerical data to an X display. Its companion program is xfim, which displays two-dimensional numerical data.
Screenshots:
Where is xgr?
The source directory is math.arizona.edu/~kerl/src/x11. A tar file is located at math.arizona.edu/~kerl/src/x11.tgz.
Why xgr?
xgr has far fewer features than, say, Matlab's plotter. It is nothing more than a quick hack. However, it has the following benefits:
- Because I wrote the code, I can create precisely those features I want.
- I/O formats are what I want them to be.
- xgr starts up quickly.
- It can read from standard input, and is scriptable.
- I can compile and run xgr on any machine with a C compiler and X11.
File formats
xgr takes as input one or more vectors, and creates an X/Y plot of them. The user specifies whether:
- the first column of the data file is the abscissa and the rest are ordinates (default), or
- all columns of the data file are ordinates and the abscissa is taken from the line number (via the -n command-line option).
For example, suppose an input data file is as follows:
1 2 3 7 5 9
With -n, xgr plots two lines: (1,1) (2,3) (3,5), and (1,2) (2,7) (3,9).
Without -n, xgr plots one line: (1,2) (3,7) (5,9).
Axes are drawn in black, but no ticks or labels are written to the display window. As a consolation, display boundaries are printed to the console.
By default, input data is ASCII in the format described above. With the -rb option, the file is treated as a single-precision floating-point binary vector. With the -cb option, the file is treated as a single-precision floating-binary pair of vectors, e.g. nominally real and imaginary parts of a complex number. With -rb or -cb, binary files are taken to be in processor-native byte order; with -rnb or -rnb, binary files are taken to be in network (big-endian) byte order.
Mouse navigation
- Left-click and release a point on the screen to have its coordinates printed to the console.
- Left-click and drag a rectangle (xgr unfortunately does not do rubber-banding) to zoom in.
- Right-click to zoom out.
- Middle click to restore the original data dimensions.
Keystrokes
- d: Toggle the existence of lines connecting the data points.
- f: Cycle the draw order of the vectors.
- r: Restore original zoom (same as middle mouse click).
- q or escape: Exit xgr.
Command-line arguments
Usage: xgr [ options ... ] {data file name}
Options include:
-c initial upper left corner x & y location in pixels
-w init. window width in pixels
-h init. window height in pixels
-xb {low x} {high x} as floats
-yb {low y} {high y} as floats
-rv (reverse video): Invert background color.
-n to take X coordinate implicitly from line number,
rather than from first column of data file.
-sort: Sort input data on X coordinate before plotting.
--help: print this message.
-a: ASCII input (default)
-rb: Real binary input
-cb: Complex binary input
-rnb: Real binary input, in network byte order
-cnb: Complex binary input, in network byte order
Use "-" as file name, or omit, to read from stdin.
Examples
This example uses some of my Perl scripts to generate and transform data.
phatgen 256 10 40 | xgr -n
phatgen 256 10 40 | pfft -fo | xgr -n
Status
I have not modified xgr recently.
xgr handles X events very naively. In particular, it handles each resize event to completion, in sequence, even if several more resize events are pending. This makes for slow redraws, particuarly when communicating with an X server over a slow network. This effect worsens as the amount of data plotted increases.
Availability
xgr is released under the terms of the GNU General Public License (GPL). Please see the file COPYING for more details. Also please visit www.gnu.org.
xgr has been run on Linux 2.4 and Solaris 5.8, compiled by GCC 3.2.2 and above. It should run on any Unix with X11 and a GCC.
Contact information
John Kerl
math.arizona.edu/~kerl
kerl at math dot arizona dot edu