gnuplot stdin, how to plot two lines?

前端 未结 9 1524
栀梦
栀梦 2020-12-09 08:13

I\'m trying to produce a plot with two lines using data taken from stdin. I have a file \"test.csv\":

0,1.1,2
1,2,3
2,6,4
4,4.6,5
5,5,6

I\

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-09 08:46

    Gnuplot can read from stdin, but for each plot statement, a new data set is required. The following works fine:

    cat test.csv | gnuplot -p -e "set datafile separator ','; plot '-' using 1:2 w l"
    

    The error appears as soon as you append the second plot command with , '' using 1:3. For this you need to send the data again as the first data set isn't stored interally for reuse. So for you two plot commands, the following snippet works fine:

    echo 'e' | cat test.csv - test.csv | gnuplot -p -e "set datafile separator ','; plot '-' using 1:2 w l, '' using 1:3 w l"
    

    That writes the data file twice, separated by an e which indicates the end of the data for the first plot command.

提交回复
热议问题