University of Virginia Department of
    Computer Science

Introduction

Jgraph is a filter for graph plotting that produces PostScript. The author, Jim Plank, describes jgraph in the README file as below:

Jgraph takes the description of a graph or graphs in the standard input, and produces a postscript file on the standard output. Jgraph is ideal for plotting any mixture of scatter point graphs, line graphs, and/or bar graphs, and embedding the output into LaTeX, or any other text processing system which can read postscript.

The graph description language is simple enough to get nice looking graphs with a minimum of effort, yet powerful enough to give the user the flexibility to tailor the appearance of the graph to his or her individual preferences. This includes plotting multiple graphs and laying them out separately on the page (or pages).

Jgraph is pretty simple to learn. Almost all the basic and advanced functionality can be found in the man page. The best way to learn jgraph is to plagiarise someone else's jgraph file and modify it to suit one's tastes. The simplest jgraph input is the file given below:

newgraph newcurve pts 0 1 1 2 2 4 3 8 4 16

This bit of jgraph code plots the points on an exponential curve.

Generating PostScript graphs using jgraph

From the command line, type "jgraph". This makes jgraph take input from the keyboard and will generate the output PostScript to the screen. Since this is not generally useful, it makes more sense to try the command:

jgraph tst.jgr > tst.ps ; ghostview tst.ps &

The file tst.jgr is the file in which you specify the points you wish to plot and the jgraph commands that enable plotting and layout of the graphs you wish to generate. The command-line shown above generates the file tst.ps which is in Encapsulated PostScript. In this format, your graph is suitable for inclusion into a LaTeX or FrameMaker document. If you wish to generate stand-alone PostScript, use the -P option at the command line.

Benefits & Downsides

The jgraph description language is easy to use. All commands are treated as whitespace-separated tokens. Most of the commands can be given in any order. Multiple graphs can be drawn on a single page. Also, jgraph can be made to use colour and different line and mark styles for various curves on the same graph.

Features not embedded within the description language are: line and function interpolation, function plotting, and pie graphs. The latter is impossible with jgraph, however, the others can be effected with jgraph and some programming or scripting language. Also, 3D graphs are not supported.

Example

Here is a solution in jgraph to exercise 1.1a from Computer Architecture A Quantitative Approach which generates the PostScript for the graph:

newgraph
xaxis label : Percent Vectorisation
yaxis label : Net Speedup
newcurve
pts
0       1
10      1.105
20      1.235
30      1.399
40      1.613
50      1.905
60      2.326
70      2.985
80      4.167
90      6.897
100     20
The following modified version of the above graph is a bit fancier.
(* A comment to demonstrate comments *)
newgraph
x_translate 1 y_translate 1 (* Let's move the graph on the page *)
title : % Vectorisation vs. Speedup
xaxis size 3 min 0 max 100 label : Percent Vectorisation
no_auto_hash_labels
hash_labels vjc hjr rotate 90   (* Placing labels well is important! *)
hash_label at   0 : Zero
hash_label at  50 : Half
hash_label at 100 : Full
yaxis size 3 min 1 max 20 log log_base 2 label : Net Speedup
newcurve marktype diamond linethickness 2 linetype dashed color 0 1 0 label : Normal Curve

pts
0       1
10      1.105
20      1.235
30      1.399
40      1.613
50      1.905
60      2.326
70      2.985
80      4.167
90      6.897
100     20

Also see



HelpNet
HelpNet was created by the 1995 incoming graduate class. It is only occasionally updated.
Department of Computer Science
School of Engineering, University of Virginia
151 Engineer's Way, P.O. Box 400740
Charlottesville, Virginia 22904-4740

(434) 982-2200  Fax: (434) 982-2214
Web Comments: webteam@cs.virginia.edu
Admissions Inquiries: inquiry@cs.virginia.edu
Site directory, Other addresses
Server statistics
© Created by the CS Web Team