gnuplotgraphing

How to plot different columns from a file in gnuplot


Say, I have a data file with N columns. How to plot using 1:2, 3:4, 5:6 & so on in gnuplot ?

For smaller N values, I tried, plot 'datafile' u 1:2 w l, '' u 3:4 w l, '' u 5:6 w l ... I got what I wanted. But clearly this isn't efficient and cumbersome.


Solution

  • plot for [N=1:*:2] 'datafile' using (column(N)):(column(N+1)) with lines
    

    The * will consume all columns in the file. The 2 will advance N by two after each plot iteration. If your columns have header information, you may want to use this to label the plots.

    plot for [N=1:*:2] 'datafile' using (column(N)):(column(N+1)) with lines title columnhead(N+1)