How to plot using specific rows of data file with Gnuplot

Last updated on September 6, 2020 by Dan Nanni

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 built-in option called every. The every option can be used with plot command in the following form:

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

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. For example, 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.

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean