gnuplot with muliple columns using loop

2019-07-25 07:04发布

I have a number of files (having 10 columns each) with following order:

file_001.txt, file_002.txt, file_003_txt,
file_021.txt, file_023.txt, file_023.txt,
file_041.txt, file_042.txt, file_043.txt,
file_061.txt, file_062.txt, file_063.txt,
file_081.txt, file_082.txt, file_083.txt,

I would like to plot each file with different line. e.g. using 1:2, using 1:3, using 1:5, using 1:8. I can not able to make a loop to call different columns. My following script is not working for k field

 plot for [k=2, 3, 5, 8] for [j=0:8:2] for [i=1:3] 'file_0'.j.i.'.txt' u 1:k;

2条回答
SAY GOODBYE
2楼-- · 2019-07-25 07:35

If j can be > 9, you should set up a function

fname(j,i) = sprintf("name%02.f%.f",j,i)

to get proper file names.

Format string "%02.f" means float (f), no digits after the comma (.), minimum two postions (2), fill empty space with zeroes.

print fname(2,3)
    name023

print fname(13,3)
    name133

print fname(113,3)
    name1133

These are libc format strings, they are not documented inside the gnuplot docs, but there are many sources in the web.

查看更多
闹够了就滚
3楼-- · 2019-07-25 07:38

Use for [k in "2 3 5 8"] if you have a list rather than a range.

查看更多
登录 后发表回答