By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,906 Members | 1,771 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,906 IT Pros & Developers. It's quick & easy.

gnuplot-py: plotoutput in string?

P: n/a
Hi,

Im using Gnuplot via gnuplot.py and Im looking for a way to get the
plotting output (terminal set to png in my case) piped in a string
instead of to stdout or a file.

Is there any method in gnuplot.py that does this for me?
If not, I tried something like:

p=Gnuplot.Gnuplot(debug=1)
p('set terminal png')
oldstdout=sys.stdout
output=cStringIO.StringIO()
sys.stdout=output
p.plot([[1,0],[2,50],[3,0],[4,20],[5,0],[6,30],[7,70], [8,70], [9, 75],
[10, 50], [11, 30], [12, 50]])
sys.stdout=oldstdout
print output.getvalue()

But unfortunately I also get other stuff like:

"gnuplot: unable to open display ''
"gnuplot: X11 aborted"

in the same string

Can anyone help me on this?

Thanks,
Nicola

Aug 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 2005-08-18, Nicola Kaiser <Ni***********@urz.uni-heidelberg.de> wrote:
Im using Gnuplot via gnuplot.py and Im looking for a way to get the
plotting output (terminal set to png in my case) piped in a string
instead of to stdout or a file.
Plotting to a file and then reading the file is pretty trivial:

import Gnuplot,time

filename = 'foo.png'
p = Gnuplot.Gnuplot()
p('set term png')
p('set out "%s"' % filename)
p.plot('sin(x)')
p('set out')
time.sleep(0.1) # wait for gnuplot to process all the commands
s = open(filename,'rb').read()

Since gnuplot is running asycnronously and reading commands
from a pipe, you've got to give it some time to finish
executing the commands before you attempt to read the file.
Is there any method in gnuplot.py that does this for me?
I don't think so.
If not, I tried something like:

p=Gnuplot.Gnuplot(debug=1)
p('set terminal png')
oldstdout=sys.stdout
output=cStringIO.StringIO()
sys.stdout=output
p.plot([[1,0],[2,50],[3,0],[4,20],[5,0],[6,30],[7,70], [8,70], [9, 75],
[10, 50], [11, 30], [12, 50]])
sys.stdout=oldstdout
print output.getvalue()
That's not going to work.

The gnuplot engine isn't a Python program. It's not writing to
sys.stdout, it's writing to Unix file descriptor 1. In order
to do things the way you're attempting to, you'd have to
redirect file descriptor 1 to a pipe before you start the
gnuplot engine, then read the plot data from the pipe.

The Gnuplot module may already be redirecting the gnuplot
processes output file descriptors, so attempting to do it
yourself might not work anyway.
But unfortunately I also get other stuff like:

"gnuplot: unable to open display ''
"gnuplot: X11 aborted"

in the same string

Can anyone help me on this?


You shouldn't have gotten messages about the X11 terminal
driver if you really had set the terminal type to png.

--
Grant Edwards grante Yow! Are you selling NYLON
at OIL WELLS?? If so, we can
visi.com use TWO DOZEN!!
Aug 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.