2014-03-25 64 views
1

我有一些數據,我想繪製在三維和二維圖。我有它具有以下形狀的數據文件:從三維數據輸入Gnuplot二維繪圖

1 1 2 
2 1 4 
3 1 6 
4 1 8 

1 2 1 
2 2 2 
3 2 3 
4 2 4 

1 3 4 
2 3 3 
3 3 2 
4 3 1 

1 4 8 
2 4 6 
3 4 4 
4 4 2 

在這種情況下,第一列是X,第二個是y和第三個是值。 其實我正在使用一個文件,它有100個單獨的矩陣,但我認爲這個例子應該稍微有點複雜。 :)

我通過使用由3D繪圖: splot「的data.txt」用1:2:3與線

另外我現在想使2D圖在兩個方向上。因此,像

plot "data.txt" using 1:3 

只使用第一矩陣

plot "data.txt" using only the first line of 2:3 in every matrix 

我發現幫助在部分1「我如何在一個文件中的數據繪製的一部分?」

對於第一種情況

plot "data.txt" every :::1:1 using 1:3 with lines 

似乎做的工作

但我不知道在第二種情況下,如何管理語法正確的方式

plot "data.txt" every ::1 using 1:3 with lines 

不會做我期望的。該圖實際上是空的或只包含一個單一的數據文件。

+0

我認爲你的第一個例子是錯誤的,它應該是'plot「data.txt」every ::: 0 :: 0 using 1:3 with lines',注意零(它在gnuplot中是第一個元素而不是1)和多餘的冒號「:」在零之間。這意味着「開始繪製塊零並以塊零結束」。 – Miguel

+0

是的,你說得對。我不好,謝謝你的評論! :) – freeone

回答

0

打字help every爲您提供瞭如何做到這一點的指導方針。不過我同意every這個選項有點尷尬。這應該這樣做:

plot "data.txt" every ::0::0 using 1:3 with lines 

它意味着「每個塊零到零的繪圖元素」。元素零是gnuplot中的第一個元素。

能夠通過線點連接,你需要使用外部工具,如awk

plot "<awk -v p=0 'n==p; NF{n++} !NF{n=0}' data.txt" u 1:3 w l 

其中p=0具有作爲every ::0::0同樣的效果。這個解決方案已經給出了here

+0

使用1:3繪製「data.txt」每個::: 0 :: 0的確可以完成這項工作,但不幸的是它並沒有連接各個點。我在[link](https://stackoverflow.com/questions/19792919/gnuplot-using-with-lines-in-combination-with-everycommand)發現了另一個討論。不幸的是,我無法得到給出的例子運行我的例子...你有任何建議嗎? – freeone

+0

您在上面的評論的開頭部分添加了一個額外的冒號。關於用線連接點,似乎沒有完全gnuplot解決方案,請參閱[this](http://stackoverflow.com/questions/19792919/gnuplot-using-with-lines-in-combination-with-everycommand)。基本上使用'plot' Miguel