From: Andreas T. <ti...@rk...> - 2002-09-10 12:29:37
|
Hello, I'd like to obtain the output from GnuPlot as string rather than as file or in a xterm for further processing with PIL or to foreward the resulting output to Zope. If output is not set gnuplot forewards it to stdout and I'm seeking for a way to grab this into any variable (string, PIL.Image or whatever) to do further processing with it. Kind regards Andreas. |
From: Michael H. <hag...@jp...> - 2002-09-10 14:56:08
|
Andreas Tille writes: > I'd like to obtain the output from GnuPlot as string rather than as > file or in a xterm for further processing with PIL or to foreward > the resulting output to Zope. What about having gnuplot write the output to a temporary file and then read the file? If you are under Unix, you could even have gnuplot write the output to a fifo (named pipe) and read it directly into your program. I don't think there is a way to get at the string any other way. One could change Gnuplot.py to read gnuplot's standard output, but I'm not sure that output would only have the pure graphics. If you want to pursue this, you would probably want to do it by providing your own substitute GnuplotProcess object. Michael -- Michael Haggerty mh...@al... |
From: Andreas T. <ti...@rk...> - 2002-09-11 05:57:58
|
On Tue, 10 Sep 2002, Michael Haggerty wrote: > What about having gnuplot write the output to a temporary file and > then read the file? Besides the possible speed constraint I'm afraid that this does not work very well in Zope. I'm a Zope beginner but I'm afraid that its Philosophy does not like disk access very much. > If you are under Unix, you could even have For sure. It's Debian GNU/Linux. > gnuplot write the output to a fifo (named pipe) and read it directly > into your program. This seems to be the best solution. But how to do that. Any example to let GnuPlot write to a named pipe and read this in a Python program? Sorry, I'm no experienced Python programmer. > I don't think there is a way to get at the string any other way. One > could change Gnuplot.py to read gnuplot's standard output, but I'm not > sure that output would only have the pure graphics. If you want to > pursue this, you would probably want to do it by providing your own > substitute GnuplotProcess object. Well at least I tried `my_program.py > image.eps` and got perfectly the same as when I set the output to image.eps. This is no proof but might be an option for further versions to include (at least for testing ...). Kind regards Andreas. |
From: Andreas T. <ti...@rk...> - 2002-09-16 15:09:32
|
On Tue, 10 Sep 2002, Michael Haggerty wrote: > What about having gnuplot write the output to a temporary file and > then read the file? If you are under Unix, you could even have > gnuplot write the output to a fifo (named pipe) and read it directly > into your program. I fiddled around something with mkfifo but failed to read it correctly. Seems there is some magic to do with threads or someting else because reading from the pipe fails completely. > I don't think there is a way to get at the string any other way. One > could change Gnuplot.py to read gnuplot's standard output, but I'm not > sure that output would only have the pure graphics. If you want to > pursue this, you would probably want to do it by providing your own > substitute GnuplotProcess object. Any hint how to do that? Kind regards Andreas. |
From: Michael H. <hag...@jp...> - 2002-09-16 17:44:52
|
Andreas Tille writes: > On Tue, 10 Sep 2002, Michael Haggerty wrote: > > > What about having gnuplot write the output to a temporary file and > > then read the file? If you are under Unix, you could even have > > gnuplot write the output to a fifo (named pipe) and read it directly > > into your program. > I fiddled around something with mkfifo but failed to read it correctly. > Seems there is some magic to do with threads or someting else because > reading from the pipe fails completely. Yes, you would probably have to read from the fifo in another python thread. > > I don't think there is a way to get at the string any other way. One > > could change Gnuplot.py to read gnuplot's standard output, but I'm not > > sure that output would only have the pure graphics. If you want to > > pursue this, you would probably want to do it by providing your own > > substitute GnuplotProcess object. > Any hint how to do that? Yes, instead of starting gnuplot with the os.popen() command, you would start it with os.popen2(). This returns the file objects (child_stdin, child_stdout). You would write the gnuplot commands to child_stdin, and you would read the child's results from child_stdout. Presumably child.stdout would have to be read from a different python thread to prevent deadlocks. You would probably have to experiment to check what other output gnuplot writes to its standard output, and when and if it flushes the output. You might have to limit yourself to plotting a single graph per gnuplot process to prevent subsequent graphs from running together. Note that os.popen2() is only available as of Python 2.0. For previous Python versions you would have to use the popen2 module. I'm not sure whether these modules are available for other OSes. If you implement this and find it to be useful, submit a patch and I'll add it to the Gnuplot.py source. Michael -- Michael Haggerty hag...@jp... |