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.
The first method is to use
gnuplot's built-in option called
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
plot "my.dat" every ::10
To plot the data from line
10 to line
plot "my.dat" every ::10::100
To plot data starting from the first line till line
plot "my.dat" every ::::100
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.
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.