繪製多個資料檔案
第一種方法 - 串聯連線
繪製多個資料檔案的最簡單方法是在 gnuplot 的 plot 命令中插入 for 迴圈。假設你有後續命名的 N 檔案,即
file_1.dat
file_2.dat
file_3.dat
...
file_N.dat
執行命令
plot for[i = 1:N] "file_".i.".dat" 
將在同一圖表中繪製 file_1.dat 和 file_N.dat 之間的所有檔案。
三個資料檔案的示例
資料集表
| X-軸 | Y-ax file_1.dat | Y 軸檔案_2.dat | Y 軸檔案_3.dat | 
|---|---|---|---|
1 | 
1 | 1 | 1 | 
2 | 
2 | 4 | 2 | 
3 | 
3 | 9 | 6 | 
4 | 
4 | 16 | 24 | 
5 | 
5 | 25 | 120 | 
命令
set terminal postscript color noenhanced ##setting the term
set output "multiple_files.ps"
set key center ##legend placement
plot [1:5][1:120] \
    for [i = 1:3] "file_".i.".dat" \
    pointsize 1.3 linecolor i+4 \
    title "file\_".i.".dat" \
    with linespoint
迴圈以 for [i = 1:3] "file_".i.".dat" 開始並執行 plot 命令直到它到達 i = 3。.i. 是連線數。
title "file\_".i.".dat" 已經用\編寫,以使檔名中的 _ 符號顯示為下劃線而不是下標,而 noenhanced 說明符是獲得此結果的基礎。
最終結果如下所示

第二種方法 - 使用 sprintf 函式
另一個可能的路徑是使用 sprintf 函式,該函式與 C 語言 sprintf 基本相同。正確的語法,從 gnuplot 的 5.1 文件是
sprintf("format", x, y, ...)
一個簡短的例子將澄清每一個疑問。
file_name(n) = sprintf("file_%d.dat", n)
plot for[i = 1:N] file_name(i) title file_name(i)