2012-05-01 46 views
0

我有大量的數據繪製的,我想要使用的gnuplot。數據是大約80000個元素的排序數組。通過簡單地使用大分組數據繪製

plot "myData.txt" using 1:2 with linespoints linetype 1 pointtype 1 

我得到的輸出,但:它需要時間來呈現,而點往往是凌亂,偶爾差距。爲了解決第二個問題,我想到做條形圖:每個條目 將對應一個條。但是,我不知道如何實現這一點。我想在連續的小節之間留出一些空間,但我不希望它會被看到。繪製數據會有什麼建議?

........................

由於數據量大,我想這是最好的小組。 請注意,我的數據看起來像

1 11041.9 
2 11041.9 
3 9521.07 
4 9521.07 
5 9520.07 
6 9519.07 
7 9018.07 
... 

我想通過一個組3,繪製數據,即,第一條垂直線應該在9521.07開始從1,2,3降到最低點,結束於11041.第二條垂直線應考慮以下3點:4,5和6,並從9519.07開始,結束於9521.07,依此類推。

可這與gnuplot的實現,給出所示的數據文件?如果是這樣,我會很感激,如果有人發佈我應該使用的一組命令。

回答

2

爲了減少gnuplot的實際繪製的點數,你可以使用關鍵字every,例如

plot "myData.txt" using 1:2 with linespoints linetype 1 pointtype 1 every 100 

將繪製每100個數據點。

我不知道是否有可能做你想做(繪製垂直線)內的gnuplot優雅的東西,但這裏是我的解決方案(假設爲UNIX-Y環境)。首先讓awk腳本稱爲sort.awk

BEGIN { RS = "" } 
{ 
# the next two lines handle the case where 
# there are not three lines in a record 
xval = $1 + 1 
ymin = ymax = $2 
# find y minimum 
if ($2 <= $4 && $2 <= $6) 
    ymin=$2 
else if ($4 <= $2 && $4 <= $6 && $4 != "") 
    ymin=$4 
else if ($6 <= $2 && $6 <= $4 && $6 != "") 
    ymin=$6 
# find y maximum 
if ($2 >= $4 && $2 >= $6) 
    ymax=$2 
else if ($4 >= $2 && $4 >= $6) 
    ymax=$4 
else if ($6 >= $2 && $6 >= $4) 
    ymax=$6 
# print the formatted line 
print ($1+1) " " ymin " " ymin " " ymax " " ymax 
} 

現在這個gnuplot的腳本將它稱爲:

set terminal postscript enhanced color 
set output 'plot.eps' 

set boxwidth 3 
set style fill solid 
plot "<sed 'n;n;G;' myData.txt | awk -f sort.awk" with candlesticks title 'pretty data' 

它不漂亮,但它的工作原理。 sed增加了一個空行,每3行,和awk格式化爲candlesticks樣式的輸出。您也可以嘗試將awk腳本嵌入到gnuplot腳本中。

+0

謝謝。我決定將這些數據進行分組,從我的問題編輯中可以看到。我希望你會有一些有用的意見。 – user506901

+0

看到我編輯的帖子。 – andyras

1

你可以做這樣的事情......(這將是最簡單的在UNIX上)。您需要每隔三行插入一個空格 - 我沒有看到任何解決方法。如果你在Unix上,命令

awk 'NR % 3 == 0 {print ""} 1' myfile 

應該這樣做。 (見How do I insert a blank line every n lines using awk?

當然,你可以(並且可能應該)組,其直接進入你的gnuplot的文件。

因此,所有說和做,你有這樣的事情:

xval(x)=int(x)/3 #Return the x position on the plot 
plot "< awk 'NR % 3 == 0 {print ""} 1' datafile" using (xval($1)):2 with lines