我正在尝试使用python脚本基于行号划分数据并调用Gnuplot来绘制直方图。但是,出于某种原因,我在运行脚本后没有得到任何输出。 有人可以帮我理解我做错了什么吗? 谢谢!
我的剧本:
#!/usr/bin/env python
import os
import subprocess
with open("gpu Latency sample 1.txt", "r") as f:
for lineno, line in enumerate(f, start=1):
if ( lineno % 2 == 0) :
#odd_file = open("odd_file.txt", 'a')
with open("even.txt", "a") as even_file:
even_file.write(line)
else :
with open("odd.txt", "a") as odd_file:
odd_file.write(line)
p = subprocess.Popen(['gnuplot'], shell = True,stdin=subprocess.PIPE )
filename1= open("even.txt","r")
filename2= open("odd.txt","r")
p.stdin.write("set xtics nomirror rotate by -45")
p.stdin.write("set key noenhanced")
p.stdin.write("set style data linespoints")
p.stdin.write("binwidth=1000")
p.stdin.write("bin(x, width)=width*floor(x/width) + binwidth/2.0")
p.stdin.write("plot \"%s\" using (bin((\$1+\$2),binwidth)): (1.0) smooth freq with lines, \"%s\" using (bin((\$1+\$2),binwidth)): (1.0) smooth freq with lines" %(filename1, filename2))
p.stdin.write("pause -1")
答案 0 :(得分:1)
你正在写gnuplot的stdin,但是你没有向它发送任何换行符(\n
):所有你的gnuplot命令都在一行中被squesting quashhed,之后甚至没有空格。
尝试在上面的"\n"
个来电结束时添加write
字符。