1 回答

TA貢獻1775條經驗 獲得超11個贊
我會做這樣的事情
# this function relates every type to an int, convenient for setting the plot styles
f(x) = x eq "type1"? 1: x eq "type2"? 2:0
# this tell gnuplot to ignore the result of lines not matching
set datafile missing "NaN"
# setting a nice style for every type
set style line 1 linetype 1 linewidth 2 pointtype 3 linecolor rgb "red"
set style line 2 linetype 1 linewidth 2 pointtype 3 linecolor rgb "blue"
# using a ternary operator to pick out the lines matching that type
plot for [i in "type1 type2"] 'test.dat' u (strcol(2) eq i?$3:NaN) w l ls f(i)
得到這個
如果需要,您可以for
從 plot 命令中刪除并僅使用plot 'test.dat' u (strcol(2) eq "type1"?$3:NaN) w l ls 1, 'test.dat' u (strcol(2) eq "type2"?$3:NaN) w l ls 2
, 為每種類型顯式繪圖,并更好地控制每條繪圖線的細節(jié)。
您可以制作另一個函數(shù)來為每一行添加標題,類似于f(x)
但返回每種類型的字符串而不是 int。
我還聽說過使用 awk 或內部函數(shù)在 gnuplot 中進行累積和的方法,您可以在此處查看gnuplot-cumulative-column-question
添加回答
舉報