0

I have data file like following:

#X1 y1 x2 y2 Number
123 567 798 900 1
788 900 87  89 2
....

and I draw my graph using following command

plot '~/Desktop/pointcolor.txt' using 1:2:($3-$1):($4-$2):5 with vectors palette nohead notitle

here is the result.

Result Graph

As you can see in above image, the result is to compressed, so I want to draw one line per ten lines which have same Number in data file.

Edit1:

I try @ewcz solution, as follow:

stat="0 0 0 0 0 0 0" # How should I define array as [gnuplot][2] didn't support it? 
plot "< awk '{if(( (stat[$5]++)%10==0 )) print}'~/Desktop/pointt.txt" using 1:2:($3-$1):($4-$2):5 with vectors palette nohead notitle

but I get this error:

gnuplot> load "gnuplot.cmd"
awk: line 1: syntax error at or near 

gnuplot> plot "< awk '{if(( (stat[$5]++)%10==0 )) print}'~/Desktop/pointcolor.txt" using 1:2:($3-$1):($4-$2):5 with vectors palette nohead notitle
                                                                                                                                       ^
         "gnuplot.cmd", line 6: warning: Skipping data file with no valid points

gnuplot> plot "< awk '{if(( (stat[$5]++)%10==0 )) print}'~/Desktop/pointcolor.txt" using 1:2:($3-$1):($4-$2):5 with vectors palette nohead notitle
                                                                                                                                              ^
         "gnuplot.cmd", line 6: x range is invalid

Edit2:

The solution:

 plot "< awk '{if((stat[$5]++)%10==0) print}' ~/Desktop/pointt.txt" using 1:2:($3-$1):($4-$2):5 with vectors palette nohead notitle
user3806649
  • 1,257
  • 2
  • 18
  • 42
  • These links use `every` option to draw line depend on the line number, how can I use this option in my case? – user3806649 Nov 13 '15 at 21:50
  • the `stat` array is internal to the invocation of `(g)awk`, the line `stat="0 0 0 0 0 0 0"` is not needed. Also, there should be a space in front of the `~` character so that `awk` can distinguish between the commands enclosed in apostrophes and the file being processed `~/Desktop/pointcolor.txt` – ewcz Nov 14 '15 at 09:02
  • I still get an error :( – user3806649 Nov 14 '15 at 09:44
  • there should be a space after the apostrophe, i.e., `plot "< awk '{if(( (stat[$5]++)%10==0 )) print}' ~/Desktop/pointt.txt" using 1:2:($3-$1):($4-$2):5 with vectors palette nohead notitle` – ewcz Nov 14 '15 at 09:47
  • I make mistake, thanks. :) – user3806649 Nov 14 '15 at 09:49

1 Answers1

2

In order to achieve this, one has to use (most likely) some kind of preprocessing of the input. Fortunately, Gnuplot allows to plot a result of a command in a straightforward way. In your case, one could modify the plot command as:

plot "< gawk '{if((stat[$5]++)%10==0) print;}' ~/Desktop/pointcolor.txt" ...

Here, the id of the row (based on the fifth column) is stored in an array stat. If this id is divisible by 10, the row is printed and thus consequently plotted (i.e., other input rows are discarded).

ewcz
  • 12,819
  • 1
  • 25
  • 47