从文件读取的python gnuplot [英] python gnuplot read from file

查看:144
本文介绍了从文件读取的python gnuplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含以下数据的文件,第一个字段是UNIXTimestamp,

i have a file with the following data the first field is UNIXTimestamp,

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?

how do i load the x,y from this file to 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)

目前这行不通...任何想法?

currently this is not working...any ideas??

更新:

#!/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)

xaxis上的时间值与图形重叠.任何想法?

The time values on xaxis are overlapping with the graph..any ideas??

推荐答案

使用Gnuplot.File代替Gnuplot.Data,可以得到以下曲线图:

Using Gnuplot.File instead of Gnuplot.Data, it is possible to get the following plot:

#!/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)


更新:

对于重叠,可以将45更改为-45:

For the overlap, you can change 45 to -45 :

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

这篇关于从文件读取的python gnuplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆