xy2ps: Convert X-Y data to PostScript format plot
sample graph

Requirement: Perl, gs(GNU Ghostscript: PostScript interpreter) or PostScript printer
(convert(1), cut(1), paste(1), sed(1), tac(1) etc. are suitable for working in harmony with xy2ps.)

0. How to install

$ wget http://members.jcom.home.ne.jp/maegawa/pub/xy2ps
$ chmod +x xy2ps
$ su
# cp xy2ps /usr/local/bin

1. Basic usage

When data is not given, xy2ps generates random X-Y data automatically.
$ xy2ps >temp.ps

Use gs(Ghostscript) for rendering.
$ gs temp.ps

Send PostsScript data to the printer.
$ lpr temp.ps

The two above-mentioned commands(xy2ps and gs) can be executed by one command as follows.
$ xy2ps -gs

Moreover, above is the same as the following.
$ xy2ps >~/.xy2ps/temp.ps && gs -q ~/.xy2ps/temp.ps

So you can output the previous graph to the printer as follows.
$ lpr ~/.xy2ps/temp.ps

Kicking the data to printer directly
$ xy2ps | lpr

Making image file
$ xy2ps -image | convert - portrait.jpg
$ xy2ps -image -landscape | convert - -rotate 90 landscape.jpg

2. Plot the graph of numerical data

2.1 Plot with "sample.dat"

$ cat sample.dat
Parabola data
0  0
1  1
2  4
3  9
4  16
5  25
6  36
7  49
8  64
9  81
10 100
$ xy2ps sample.dat -gs

2.2 Read data from standard input

(OK)
$ cat sample.dat | xy2ps - >temp.ps && gs -q temp.ps

(NG)
$ cat sample.dat | xy2ps - -gs
$ cat sample.dat | xy2ps - | gs -

(OK)
$ gs `locate tiger.ps`
(NG)
$ cat `locate tiger.ps` | gs -

3. Decoration

-no_pedantic
$ xy2ps -no_pedantic -gs

with various command line options to control plot(see `xy2ps -h`, `xy2ps -h2`)
$ xy2ps sample.dat -gs -xmin 0 -xmax 10 -xtick 5 -xsubt 5 -ymin 0 -ymax 100 -ytick 50 -ysubt 5 -xtitle "X axis name" -ytitle "Y axis name" -gtitle "Graph Title" -lwidth 1.2 -psym 8 -psize 7 -lcolor 1

specify line style, color, width
$ xy2ps data-file -xyxy -gs -only_axis -lwidth ".5|.5|4" -lstyle "2|1|0" -lcolor "0|2|1"

4. Multi lines

4.1 xyyy type multi column data

    x y1 y2 y3...
    :
    :
$ ./mkxy_0 > two-lines.dat
$ xy2ps two-lines.dat -gs -no_pedantic -label "exp(-x/5)*sin(x)|exp(-x/5)" -legend_x 0.5 -legend_y 0.05

$ ./mkxy_1 > multi-lines.dat
$ xy2ps multi-lines.dat -gs -psym 1 -voffset 150

4.2 xyxy type multi column data

    x1 y1 x2 y2 x3 y3...
    :
    :
$ ./mkxy_2 > xyxy-data
$ xy2ps xyxy-data -gs -xyxy -only_data -no_lstyle

4.3 Data point number of the each column

$ cat points.dat
1	1	1
2	4	8
3	9	27
4	16	64
5	25	125
6	36
7	49
8	64
9	81
10	100
$ xy2ps points -xlog -ylog -gs
-xyxy type ...same.
    x1_1  y1_1  x2_1  y2_1  x3_1 y3_1
    x1_2  y1_2  x2_2  y2_2  x3_2 y3_2
    x1_3  y1_3  x2_3  y2_3
    x1_4  y1_4  x2_4  y2_4
    x1_5  y1_5
    x1_6  y1_6
$ ./mkxy_3 100 0.25 >_1
$ ./mkxy_3  50 0.50 >_2
$ ./mkxy_3  25 1.50 >_3
$ ./mkxy_3  10 2.00 >_4
$ ./mkxy_3   5 3.00 >_5
$ paste _[1-5] > _all
$ xy2ps _all -xyxy -psym 2 -label "line-1|line-2|line-3" -no_tick -gs
Note that the column with many data point must be located in left-hand side.

4.4 Choose specified field of multi-columned data

You can select any data column by cut(1) command.
$ cut -f7,8 _all | xy2ps - >w.ps && gs -q w.ps

4.5 CSV; Comma Separated Value

The xy2ps disregards the comma(,) in data file. The CSV form data can be dealt with by using sed(1) command.
$ cat csv.dat
1,1,1
2,4,8
3,9,27
4,16,64
5,25,125
$ sed 's/,/ /g' csv.dat | xy2ps - >w.ps && gs -q w.ps

5. Command line option in data file

You can write command line option in data file.
$ xy2ps population | convert - pop.jpg

The option in data file can be disregarded by -no_file_option
$ xy2ps population -no_file_option -gs

The option in data file can be overwritten by the command line option.
$ xy2ps population -ylog -ymin 10 -ymax 10000 -legend_x 0.05 -legend_y 0.12 -npp -no_psym | convert - pop_log.jpg

Option file and Data file can be separated.
$ for i in `seq 1 5`;do xy2ps -stderr_data >/dev/null 2>_$i; done; paste _[1-$i] >data-file
$ cat option-file data-file | xy2ps - >w.ps && gs -q w.ps


This is one of the very simple execution forms. By changing 'mkgraph', any parameters are controllable.
$ ./mkgraph | xy2ps - -landscape -image | convert - -rotate 90 freevib.png
$ ./mkgraph | xy2ps - >w.ps && gs -q w.ps

6. Help

You can see usage message or more information as follows.
$ xy2ps -help
$ xy2ps -more
$ xy2ps -table
$ xy2ps -builtin

7. Why xy2ps?

Please imagine performing such work in the GUI environment.
$ ls *.dat | wc -l
    100
$ for data in *.dat; do xy2ps $data | lpr; done
Probably, gnuplot will finish the same thing more efficient more beautifully and more wonderfully! However, 95% of what I want to do can be performed by 5% of gnuplot's function. It is *NOT* a bad thing, but... .



Addition
$ ./piechart test.dat | convert - pc.png
$ ./piechart -gs -doughnut -no_outline -only_ratio test2.dat

I would like to thank the autor of the Linux, Perl, gs, emacs, and many GNU tools..
-Home- -The program under construction-

inserted by FC2 system