469,621 Members | 1,822 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,621 developers. It's quick & easy.

Controlling gnuplot via subprocess.Popen

I am trying to plot something in gnuplot 4.2 using co-ordinates a Python
2.5 program computes. Here's what I'm doing:

pyfrom subprocess import *
pyplot = Popen("c:/progs/gp/bin/wgnuplot.exe", stdin=PIPE)
pyplot.stdin.write("plot x*x")

The first command dutifully opens gnuplot, but the second doesn't do
anything. Could someone favour me with an explanation as to the whyness?

--
Peter
Apr 25 '07 #1
3 3647
On 2007-04-25, Peter Beattie <Pe***********@web.dewrote:
I am trying to plot something in gnuplot 4.2 using co-ordinates a Python
2.5 program computes. Here's what I'm doing:

pyfrom subprocess import *
pyplot = Popen("c:/progs/gp/bin/wgnuplot.exe", stdin=PIPE)
pyplot.stdin.write("plot x*x")

The first command dutifully opens gnuplot, but the second doesn't do
anything. Could someone favour me with an explanation as to the whyness?
I think it may just be that you need a newline after "plot x*x", i.e.

plot.stdin.write("plot x*x\n")

or

print >>plot.stin, "plot x*x"

But some interactive programs need to be controlled with expect rather
than just writing to their stdin. I'm unclear of the details, perhaps
it's just ones that use curses in some form.

I usually write the gnuplot commands to a file, and then use
os.system("gnuplot plot.gpi") to run gnuplot in batch mode (or gnuplot
-persist if you want the window). You can also use Popen instead of
os.system.
Apr 25 '07 #2
Peter Beattie wrote:
I am trying to plot something in gnuplot 4.2 using co-ordinates a Python
2.5 program computes. Here's what I'm doing:

pyfrom subprocess import *
pyplot = Popen("c:/progs/gp/bin/wgnuplot.exe", stdin=PIPE)
pyplot.stdin.write("plot x*x")

The first command dutifully opens gnuplot, but the second doesn't do
anything. Could someone favour me with an explanation as to the whyness?
Why re-invent the wheel? Not trying to be pedantic, but usually the
google search

"python %s" % thing_im_working_on

will yield lucrative results that far exceed anything you can create in
a reasonable amount of time. For example, "python gnuplot" first hit is:

http://gnuplot-py.sourceforge.net/

And speaking from experience, it works beautifully.

James
Apr 25 '07 #3
On 2007-04-25, Peter Beattie <Pe***********@web.dewrote:
I am trying to plot something in gnuplot 4.2 using co-ordinates a Python
2.5 program computes. Here's what I'm doing:

pyfrom subprocess import *
pyplot = Popen("c:/progs/gp/bin/wgnuplot.exe", stdin=PIPE)
pyplot.stdin.write("plot x*x")

The first command dutifully opens gnuplot, but the second doesn't do
anything. Could someone favour me with an explanation as to the whyness?
wgnuplot.exe doesn't read commands from stdin. However,
pgnuplot.exe does (that's why it exists).

It's probably easier to just use the gnuplot-py module:

http://gnuplot-py.sourceforge.net/

The "released" 1.7 version still uses Numeric. I believe
that it's been converted over to numpy, so if you prefer numpy
over Numeric, you can grab an SVN snapshot.

--
Grant Edwards grante Yow! My face is new, my
at license is expired, and I'm
visi.com under a doctor's care!!!!
Apr 25 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by madpython | last post: by
9 posts views Thread by Clodoaldo Pinto Neto | last post: by
12 posts views Thread by Eric_Dexter | last post: by
1 post views Thread by Mrown | last post: by
7 posts views Thread by skunkwerk | last post: by
25 posts views Thread by Jeremy Banks | last post: by
1 post views Thread by Mark Shewfelt | last post: by
5 posts views Thread by thedsadude | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.