Friday, September 19, 2008

Using GNUPlot

GNU plot is one of the most useful applications on Linux for creating plots. GNU plot takes in data in the following format

10 324.12 12312 56
100 34231.3 2312123 67

There are three columns here, there can be any number, make sure the data is separated by a space. You can make your program write the data directly in a file, call it whatever you want to, e.g. "simout.dat"

# Fire gnuplot
gnuplot>

# draw using the first two columns from the data file
gnuplot> plot "simout.dat" using 1:2

# draw using the first and second col AND first and third col.
gnuplot> plot "simout.dat" using 1:2, "simout.dat" using 1:3

#draw using lines
gnuplot> plot "simout.dat" using 1:2 with lines, "simout.dat" using 1:3 with lines

# draw using points on the lines
gnuplot> plot "simout.dat" using 1:2 with linespoint, "simout.dat" using 1:3 with linespoint

# draw with a legend for the lines
gnuplot> plot "simout.dat" using 1:2 with linespoint ti "Marks in CA", "simout.dat" using 1:3 with linespoint ti "Marks in WUC"

# set title
set title "The title of the plot"

# set X label
set xlabel "Blocks (N)"

# Set Y label
set ylabel "Performance [MFlops]"

# Set x and y Range
set xrange [100:10000]
set yrange [0:10e6]

# Set log scale on X
set logscale x

There are so many other things that you can do with GNUPlot, which I even don't know as I am still learning how to use it.

Excellent tutorial here (that is how I got started).

2 comments:

Asanka P. Sayakkara said...

Thanks for this post!

Piyush Garyali said...

I am glad it was useful.