2012-03-02 87 views
30

我在一些文本文件中有數據,它有10000行和2列。我知道我可以通過plot "filename.txt" using 1:2 with lines輕鬆地繪製它。我想要的只是繪圖,讓我們說從1000到2000行或任何其他合理的選擇。有沒有可能輕鬆做到這一點?非常感謝你提前。Gnuplot從一個文件繪製數據直到某一行

+0

也許這也可以幫助你: http://stackoverflow.com/questions/6564561/gnuplot-conditional-plotting-plot-col-acol-b-if-col-cx – 2016-11-07 23:27:11

回答

26

簡單:

plot "<(sed -n '1000,2000p' filename.txt)" using 1:2 with lines 
+1

是否有任何不錯的在線的東西,我可以學習這種小令人敬畏的技巧。感謝您的答覆btw。 – YBE 2012-03-02 16:38:57

+0

@YBE我建議[本網站](http://t16web.lanl.gov/Kawano/gnuplot/index-e.html)。 – kev 2012-03-02 16:41:10

+0

@kev斷開鏈接 – 2016-08-17 19:36:36

58

看來,gnuplot的將"every" command是你在找什麼:

plot "filename.txt" every ::1000::2000 using 1:2 with lines 

另外,前處理文件來選擇你感興趣的行。例如,使用AWK:

awk "NR>=1000 && NR<=2000" filename.txt > processed.txt 

然後在你現有的gnuplot命令/腳本中使用所產生的 「processed.txt」。

+0

如果您在linux或者mac osx,你應該已經有awk了(它是標準* nix工具集的一部分,比如sed和grep)。我將首先運行上述命令作爲預處理步驟(在啓動gnuplot之前),它將創建一個新的數據文件「processed.txt」,同時保留現有文件不受傷害。您應該在繪圖命令中使用「processed.txt」來代替「filename.txt」。 awk的手冊可以在這裏找到:http://www.gnu.org/software/gawk/manual/gawk.html – 2012-03-02 16:44:08

+5

+1本地gnuplot解決方案 – Pankrates 2014-06-14 19:42:12

0

我會推薦一些命令行工具,如sedgrepbash。在您的例子

head -n 2000 ./file.data > temp.data 

tail -n 1000 temp.data > temp2.data 

可能會奏效。但是還沒有測試過這麼多的數字是在頭部還是尾部工作。

6

你或許可以切出的外部工具的依賴,使用僞列0

看到help plot datafile using pseudocolumn

試着這麼做(如果你的系統沒有安裝它們爲例):

LINEMIN=1000 
LINEMAX=2000 

#create a function that accepts linenumber as first arg 
#an returns second arg if linenumber in the given range. 
InRange(x,y)=((x>=LINEMIN) ? ((x<=LINEMAX) ? y:1/0) : 1/0) 

plot "filename.txt" using (InRange($0,$1)):2 with lines 

(上的Gnuplot 4.4.2測試和Linux)

1

的Gnuplot忽略NaN值。這適用於我在x座標的指定範圍內。不知道如何指定行範圍。

cutoff(c1,c2,xmin,xmax) = (c1>=xmin)*(c1<=xmax) ? c2 : NaN 
plot "data.txt" u 1:(cutoff(($1),($2),1000,2000)) 
相關問題