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

gnuplot

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 two datasets in one plot with the titles given on the first line of each dataset?

Best Answer

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)
Related Topic