Search code examples
gnuplot

Counting number of plotted points in gnuplot


The data file contains values in the following format:

0 0 50
0 1 70
1 0 40
1 1 70
2 0 110
2 1 60
3 0 60
3 1 120
4 0 50
4 1 50
5 0 70
5 1 70

This is a code snippet from my gnuplot script:

plot 'file' using ($3 > 100 && $2 == 0 ? $1 : 1/0): 3 with points pointtype 1,\
     'file' using ($3 > 100 && $2 == 1 ? $1 : 1/0): 3 with points pointtype 2 

Can someone suggest a way to count the number of plotted points of each pointtype?


Solution

  • This is relatively easy to do by setting a counter, then do counter = counter + 1 when your condition is satisfied (I've removed the style for compactness):

    minval = 100; count1 = 0; count2 = 0
    plot 'file' using ($3 > minval && $2 == 0 ? (count1 = count1 + 1, $1) : 1/0):3, \
    'file' using ($3 > minval && $2 == 1 ? (count2 = count2 + 1, $1) : 1/0):3
    
    gnuplot> print count1, count2
    1 1
    
    minval = 50; count1 = 0; count2 = 0
    plot 'file' using ($3 > minval && $2 == 0 ? (count1 = count1 + 1, $1) : 1/0):3, \
    'file' using ($3 > minval && $2 == 1 ? (count2 = count2 + 1, $1) : 1/0):3
    
    gnuplot> print count1, count2
    3 5