2

I am trying divide the data based on line numbers using a python script and invoking Gnuplot to plot a histogram. However, for some reason, I don't get any output after running my script. Can somebody help me understand what am I doing wrong? Thanks!

My script:

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

1 Answer 1

1

You are writing to gnuplot's stdin, but you are not sending any newline (\n) characters to it: all your gnuplot commands are sgetting quashed in a single line without even a whitespace between then.

Just try adding a "\n" character at the end of each of your write calls above.

Sign up to request clarification or add additional context in comments.

1 Comment

(please, consider marking the answer as correct then)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.