1

How to use gnuplot with python3x on Windows. I have been using follwoing code.

import subprocess
proc = subprocess.Popen(['Patho to gnuplot executable','--persist'], 
                    shell=False,
                    stdin=subprocess.PIPE,
                    )
proc.stdin.write(b'set xrange [0:10]; set yrange [-2:2] \n')
proc.stdin.write(b'plot sin(x) \n')
proc.stdin.write(b'quit \n') 

1 Answer 1

1

I think it should work nearly the way you described it. The only thing you forgot is to close the pipe, so that your lines are actually processed by gnuplot. Can't test it on Windows at the moment, but on Linux the following works fine (only thing changed is the added last line):

import subprocess
proc = subprocess.Popen(['Patho to gnuplot executable','--persist'], 
                shell=False,
                stdin=subprocess.PIPE,
                )
proc.stdin.write(b'set xrange [0:10]; set yrange [-2:2] \n')
proc.stdin.write(b'plot sin(x) \n')
proc.stdin.write(b'quit \n')
proc.stdin.close()

Edit to answer the second "question" (please do not post your clarifications as answers, simply comment or edit your initial question):

There should not be a default "Popen" function. It seems to me that you have imported it in a different way than in your code snippet. For example

from subprocess import Popen

would import only the Popen module but directly into the symbol table of your python program (instead of the subprocess module). Refer to e.g. https://docs.python.org/3/tutorial/modules.html for more informations.

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

Comments

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.