python gnuplot 从文件中读取

标签 python linux gnuplot

我有一个包含以下数据的文件,第一个字段是 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?

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

目前这不起作用...有什么想法吗??

更新:

#!/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 轴上的时间值与图形重叠..有什么想法吗??

最佳答案

使用 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)


更新:

对于重叠,您可以将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

关于python gnuplot 从文件中读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13204764/

相关文章:

python - 如何在 Google Colab 上创建和使用自定义 OpenAI Gym 环境?

python - 如何包含外部 Python 代码以在其他文件中使用?

linux - 用于运行和测试 ssh 命令的 Unix 编辑器

linux - 将结构体实例重新声明为相同的变量名将返回 golang 中的旧对象

c - 从 C 程序到 Gnuplot 的管道数据问题

qt - 通过qt在gnuplot中保存pdf输出

Python:带三角函数的小数

python - 处理类内的错误,但在其他脚本中引发?

linux - Linux中新进程和新线程创建期间共享哪些资源以及创建哪些资源?

C++将字符串传递到管道中以传递给gnuplot