gnuplot conditional plotting with if

后端 未结 1 538
执念已碎
执念已碎 2020-12-11 13:25

I have a data file with two columns

10  0.5
20  0.8
25  0.3
15  0.6

I want to plot the second column if the first column is less than or e

相关标签:
1条回答
  • 2020-12-11 13:50

    To skip a point in gnuplot you must give it an invalid value like 1/0:

    plot 'data.txt' u 1:($1 <= 20 ? $2 : 1/0) with points
    

    For some plotting styles the presence of invalid values deserves some attention. If the remaining points should be connected e.g. with lines, the line is interrupted at an invalid point.

    Since gnuplot version 5.0.6 one can use set datafile missing NaN to treat invalid points like missing ones. The filtered data then behaves as if the invalid points don't exist. See https://stackoverflow.com/a/46070360/2604213 for a working example.

    0 讨论(0)
提交回复
热议问题