How to plot using specific rows of data file with Gnuplot

In many cases you probably want to filter a raw data file in various fashions before plotting the data with Gnuplot. In some cases, you may want to use only specific rows (e.g., from line 10 to 100) of a data file in your plot. With gnuplot, you can specify a range of data to plot in two different ways.

Method One

The first method is to use gnuplot's "every" option in the plot command. The "every" option is used in the following form:

plot "my.dat" every A:B:C:D:E:F

A: line increment
B: data block increment
C: The first line
D: The first data block
E: The last line
F: The last data block

To plot the data starting from line 10:

plot "my.dat" every ::10

To plot the data from line 10 to line 100:

plot "my.dat" every ::10::100

To plot data starting from the first line till line 100:

plot "my.dat" every ::::100

Method Two

An alternative way to plot specific rows of data file is to use input redirection. That is, use any external program to process raw data file, and redirect the output to gnuplot. Assuming that sed is installed on your Linux system, you can simply do:

plot "<(sed -n '10,100p' my.dat)"

As you can imagine, sed program prints out data between line 10 and line 100, and feeds it to gnuplot for plotting.

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

One thought on “How to plot using specific rows of data file with Gnuplot

  1. Really helpful information! I just wanted to comment that Gnuplot starts counting at zero, so if you want to print from your tenth row of data onwards, including this tenth row, you'll have to write

    plot 'my.dat' every ::9

Leave a comment

Your email address will not be published. Required fields are marked *