Thursday, December 16, 2010

Gnuplot - Indexed Datafiles

If you don't want to plot all lines in a datafile there is a way in gnuplot to achieve that called indexed datafiles. It requires though a certain datafile format and is not always applicable.

Here I present an easy example how to use indexed datafiles.

The main idea is that you want to split the rows in a datafile into chunks and plot only one or more chunks of these. The - probably not so easy to fulfill - requirement is that data chunks are separated by two empty lines. The chunks are indexed (starting at 0, thus the name indexed datafile) and can be used in a plot statement as described further down.

Consider this example (call it indexed.dat):
20
3
17


34
40
25


14
10
15

The gnuplot code and its generated graphs


set term png medium size 200,200

set yrange [0:*]
unset key

# generate a graph from the first chunk of data
set output 'indexed1.png'
set title 'first data set'
plot 'indexed.dat' index 0 using 1 with lines

# generate a graph from the second chunk of data
set output 'indexed2.png'
set title 'second data set'
plot 'indexed.dat' index 1 using 1 with lines

# generate a combined graph from the second 
# and third chunk of data
set output 'indexed3.png'
set title "second and third\n data set"
plot 'indexed.dat' index 1:2 using 1 with lines


No comments:

Post a Comment