2012-11-03 114 views
1

閱讀我有以下數據的第一個字段是UNIXTimestamp文件,蟒蛇GNUPLOT從文件

1351734672.095 25 
1351734674.449 52 
1351734676.638 612 
1351734680.669 44 
1351734681.121 16 
1351734684.182 15 
1351734684.386 17 
1351734686.823 16 
1351734689.807 22 
1351734689.807 28 

我如何從這個文件加載X,Y到Python?

#!/usr/bin/env python 

from numpy import * 
import Gnuplot 

g = Gnuplot.Gnuplot() 
g.title('My Systems Plot') 
g.xlabel('Date') 
g.ylabel('Value') 
g('set term png') 
g('set out "output.png"') 
proc = open("response","r") 
databuff = Gnuplot.Data(proc.read(), title="test") 
g.plot(databuff) 

目前這不工作...任何想法??

UPDATE:

#!/usr/bin/env python 
from numpy import * 
import Gnuplot 

g = Gnuplot.Gnuplot() 
g.title('My Systems Plot') 
g.xlabel('Date') 
g.ylabel('Response') 
g('set auto x') 
g('set term png') 
g('set out "output.png"') 
g('set timefmt "%s"') 
g('set xdata time') 
g('set xtic rotate by 45 scale 1 font ",2"') 
g('set key noenhanced') 
g('set format x "%H:%M:%S"') 
g('set grid') 


databuff = Gnuplot.File("repo", using='1:2',title="test") 
g.plot(databuff) 

enter image description here

的時間上x軸的值與graph..any想法重疊??

回答

3

使用Gnuplot.File而不是Gnuplot.Data,就可以得到下面的情節:

output.png

#!/usr/bin/env python 

#from numpy import * 
import Gnuplot 

g = Gnuplot.Gnuplot() 
g.title('My Systems Plot') 
g.xlabel('Date') 
g.ylabel('Value') 
g('set term png') 
g('set out "output.png"') 
#proc = open("response","r") 
#databuff = Gnuplot.Data(proc.read(), title="test") 

databuff = Gnuplot.File("response", using='1:2',with_='line', title="test") 
g.plot(databuff) 


UPDATE:

有關重疊,你可以改變45-45

#g('set xtic rotate by 45 scale 1 font ",2"') 
g('set xtic rotate by -45 scale 1 font ",2"') 

enter image description here

+1

沒有必要在這裏導入numpy的。否則+1,比我的回答好。 – mgilson

+0

我評論過'numpy import'行 –