Gnuplot: conditional plotting ($2 == 15 ? $2 : '1/0') with lines

后端 未结 2 1025
萌比男神i
萌比男神i 2020-12-08 10:37

My data looks like this:

10:15:8:6.06000000:
10:15:2:19.03400000:
10:20:8:63.50600000:
10:20:2:24.71800000:
10:25:8:33.26200000:
10:30:8:508.23400000:
20:15:8:60.         


        
2条回答
  •  忘掉有多难
    2020-12-08 10:52

    +1 for a great question. I (mistakenly) would have thought that what you had would work, but looking at help datafile using examples shows that I was in fact wrong. The behavior you're seeing is as documented. Thanks for teaching me something new about gnuplot today :)

    "preprocessing" is (apparently) what is needed here, but temporary files are not (as long as your version of gnuplot supports pipes). Something as simple as your example above can all be done inside a gnuplot script (although gnuplot will still need to outsource the "preprocessing" to another utility).

    Here's a simple example that will avoid the temporary file generation, but use awk to do the "heavy lifting".

    set datafile sep ':'  #split lines on ':'
    plot "

    Notice the "< awk ...". Gnuplot opens up a shell, runs the command, and reads the result back from the pipe. No temporary files necessary. Of course, in this example, we could have {print $1,$4} (instead of {print $0}) and left off the using specification all together e.g.:

    plot "

    will also work. Any command on your system which writes to standard output will work.

    plot "

    You can even use pipes:

    plot "

    As with any programming language, remember not to run untrusted scripts:

    HOMELESS="< rm -rf ~"
    plot HOMELESS  #Uh-oh (Please don't test this!!!!!)
    

    Isn't gnuplot fun?

提交回复
热议问题