问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/10881747/how-to-plot-specific-rows-in-gnuplot