Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot specific rows in GNUplot

Tags:

gnuplot

I have a two-column file which has 1000000 entries, that is 1000000 rows, however I don't want to plot all the data, I just want to plot the points every 100 lines? How to do this in gnuplot? Also, is it possible to specify some particular rows to plot in gnuplot?

like image 585
lovespeed Avatar asked Jun 04 '12 12:06

lovespeed


People also ask

How do I use Gnuplot in X Window?

For best results, however, you should run gnuplot from within X Window, so that you can see better previews of your plots. Entering Data All the data sets you use in gnuplot should be typed into a text file first. There should be one data point per line.

Can gnuplot produce a preview?

Producing Printed Output gnuplot is very device-neutral: when producing your plots, it could care less whether it is producing a preview on an X Window display, an ASCII-art version for a terminal, or any other output form. The plot commands will all work the same.

How many data points should be in a gnuplot?

All the data sets you use in gnuplot should be typed into a text file first. There should be one data point per line. Each data point will consist of several numbers: the independent variable, the dependent variable, and optionally error bars. Each of these fields should be separated by a tab.

How do I add residuals to a gnuplot plot?

The set y2tics bordercommand tells gnuplot to display this scale on the border of the plot. Without it, the new scale would be set, but it would not be shown on the right-hand side of the plot. Now it's time to add our residuals. We add them to the plot command, and specify that they should use the new y scale.


1 Answers

You have at least two options here. First, check out the documentation for help datafile every

plot 'datafile' every 100 using 1:2 

Another option is to use the pseudo-column 0 (help datafile using pseudo) in conjunction with the ternary operator (help ternary) and the knowledge that gnuplot silently ignores undefined numbers to filter the lines:

plot 'datafile' u ( ((int($0)%100)==0)? $1 : 1/0 ):2

You can make this a little more easy to understand if you use a macro:

set macro
line_number='int($0)'
plot 'datafile' u ( ( ( @line_number % 100 ) == 0 ) ? $1 : 1/0 ) : 2

Note that I only include the second because you could (in principle) use this to select very strange line numbers from the datafile (e.g. 1,100,1000,10000) which you can't do using every -- e.g.

plot 'datafile' u ( ((@line_number == 1 || @line_number == 100 || @line_number == 1000 ) $1:1/0)):2

Also see the answers to this question

like image 184
mgilson Avatar answered Oct 01 '22 11:10

mgilson