Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Python调用Gnuplot_Python_Gnuplot - Fatal编程技术网

从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):

我尝试使用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")

您正在写入gnuplot的stdin,但没有向其发送任何换行符(
\n
):所有gnuplot命令都在一行中被撤销,其间甚至没有空格


试着在你的写/<代码>结束时添加一个<代码>“\n”/代码>字符。< /P>(请考虑将答案标记为正确)