Search code examples
loopsgnuplotaxes

gnuplot plot loop through axes


While plotting in gnuplot, is there a way to loop through axes? Something like this:

var_axes="x1y1 x1y2" plot for [i=1:2] datafile using 1:2 axes word(var_axes,i)

It complains: "axes must be x1y1, x1y2, x2y1 or x2y2"


Solution

  • You can construct your plot command in a string variable, and then use eval to execute it:

    var_axes="x1y1 x1y2"
    cmd = "plot "
    do for [i=1:2] {
       cmd = cmd . "datafile using 1:2 axes "   . word(var_axes,i)
       if (i < 2) {
         cmd = cmd . ", "
       }
    }
    eval cmd