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.


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:

File formats

xgr takes as input one or more vectors, and creates an X/Y plot of them. The user specifies whether:

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


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.


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


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.


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
kerl at math dot arizona dot edu

Last updated: 2005-07-26