2013-02-06 102 views
2

我試圖找出如何使下面的代碼工作,而無需將數據進行多次打印(和分離與「E」副本):使用繪製多列「 - 」

plot '-' using 1:2, '-' using 1:3 
-1 0.000679244 0.000246399 
-0.99875 0.000687629 0.000251162 
-0.9975 0.000696107 0.000256024 
-0.99625 0.000704678 0.000260987 
-0.995 0.000713343 0.000266052 
-0.99375 0.000722103 0.000271221 
-0.9925 0.00073096 0.000276496 
-0.99125 0.000739913 0.000281879 
-0.99 0.000748965 0.000287372 

的上面的代碼生成錯誤消息:

warning: Skipping data file with no valid points 

我知道,我可以將數據寫入到一個文件,並調用plot 'file'多次。有沒有辦法避免這種情況?謝謝!

回答

1

沒有(好)的方法來做到這一點。這裏有一個很醜陋的黑客:

s = "-1 0.000679244 0.000246399\n-0.99875 0.000687629 0.000251162\n-0.9975 0.000696107 0.000256024\n-0.99625 0.000704678 0.000260987\n-0.995 0.000713343 0.000266052\n-0.99375 0.000722103 0.000271221\n-0.9925 0.00073096 0.000276496\n-0.99125 0.000739913 0.000281879\n-0.99 0.000748965 0.000287372" 

plot sprintf('<echo "%s"',s) using 1:2, sprintf('<echo "%s"',s) using 1:3 

看來,我們可以把它用在我們的字符串使用續行看起來有點漂亮...:

inline_file ="\ 
-1 0.000679244 0.000246399\n \ 
-0.99875 0.000687629 0.000251162\n \ 
-0.9975 0.000696107 0.000256024\n \ 
-0.99625 0.000704678 0.000260987\n \ 
-0.995 0.000713343 0.000266052\n \ 
-0.99375 0.000722103 0.000271221\n \ 
-0.9925 0.00073096 0.000276496\n \ 
-0.99125 0.000739913 0.000281879\n \ 
-0.99 0.000748965 0.000287372" 

plot sprintf('<echo "%s"',inline_file) using 1:2, \ 
    sprintf('<echo "%s"',inline_file) using 1:3 
+0

這確實不是很漂亮,但工程!感謝您提供您的見解! –

0

從版本5.0 gnuplot的支持數據塊,它可以讓你更好地處理內嵌數據:

$data <<EOD 
-1 0.000679244 0.000246399 
-0.99875 0.000687629 0.000251162 
-0.9975 0.000696107 0.000256024 
EOD 
plot $data u 1:2, '' u 1:3