从Python调用Gnuplot
我尝试使用python脚本根据行号划分数据,并调用Gnuplot绘制直方图。但是,由于某些原因,我在运行脚本后没有得到任何输出。 有人能帮我理解我做错了什么吗? 谢谢 我的剧本:从Python调用Gnuplot,python,gnuplot,Python,Gnuplot,我尝试使用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):
#!/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")
您正在写入gnuplot的stdin,但没有向其发送任何换行符(
\n
):所有gnuplot命令都在一行中被撤销,其间甚至没有空格
试着在你的