How to plot several datasets with titles from one file in Gnuplot?

前端 未结 5 1845
心在旅途
心在旅途 2020-12-04 18:28

Assuming I have a file that looks like this:

\"p = 0.1\"
1 1
3 3
4 1


\"p = 0.2\"
1 3
2 2
5 2

Is it possible to make Gnuplot plot these tw

5条回答
  •  死守一世寂寞
    2020-12-04 18:35

    It's definitely possible and your datafile is already the correct format. The functionality you're looking for is built into columnheader(N) which reads the data at the top of the N'th column and uses it as the plot title:

     plot 'test.dat' i 0 u 1:2 w lines title columnheader(1),\
          'test.dat' i 1 u 1:2 w lines title columnheader(1)
    

    which can be condensed using iteration:

    plot for [IDX=0:1] 'test.dat' i IDX u 1:2 w lines title columnheader(1)
    

提交回复
热议问题