如何使用 for 循环 gnuplot 命令

how to use for loop gnuplot command

我使用下面的 gnuplot 命令绘制轨迹

plot -22.5 lw 3,22.5 lw 3, 'hydro_15/hydro_15.01/tracer_com.dat' u (($2)**2+($3)**2)**0.5:4 w l lc 'black','hydro_15/hydro_15.02/tracer_com.dat' u (($2)**2+($3)**2)**0.5:4 w l lc 'orange','hydro_15/hydro_15.03/tracer_com.dat' u (($2)**2+($3) **2)**0.5:4 w l lc 'violet','hydro_15/hydro_15.04/tracer_com.dat' u (($2)**2+($3)**2)**0.5:4 w l lc 'red' ,'hydro_15/hydro_15.05/tracer_com.dat' u (($2)**2+($3)**2)**0.5:4 w l lc 'cyan','hydro_15/hydro_15.06/tracer_com.dat' u (($2)**2+( $3)**2)**0.5:4 w l lc 'blue','hydro_15/hydro_15.07/tracer_com.dat' u (($2)**2+($3)**2)**0.5:4 w l lc 'green','hydro_15/hydro_15.08/tracer_com.dat' u (($2)**2+($3)**2)**0.5:4 w l lc 'magenta','hydro_15/hydro_15.09/tracer_com.dat' u (($2)**2 +($3)**2)**0.5:4 w l lc 'brown','hydro_15/hydro_15.10/tracer_com.dat' u (($2)**2+($3)**2)**0.5:4 w l lc 'coral'

我可以使用 for 循环或其他方法缩短它吗?有时我有 40 个文件要绘制,这使得命令非常冗长

由于您按名称使用了不同的颜色,我假设您想将所有数据文件绘制到一张图中(没有不同的帧或动画等)

你可以这样做:(假设你的文件有两位数字,范围从 0109

脚本:

### plotting files in a loop into one graph
reset session

myFile(i) = sprintf('hydro_15/hydro_15.%02d/tracer_com.dat',i)

myColors = "black orange violet red cyan blue green magenta brown"
myColor(i) = word(myColors,i)

myCalc(col1,col2) = sqrt(column(col1)**2 + column(col2)**2)

plot -22.5 lw 3, \
      22.5 lw 3, \
      for [i=1:9] myFile(i) u (myCalc(2,3)):4 w l lc myColor(i)
### end of script