473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

gnuplot-py: plotoutput in string?

Hi,

I´m using Gnuplot via gnuplot.py and I´m 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
1 3337
On 2005-08-18, Nicola Kaiser <Ni***********@urz.uni-heidelberg.de> wrote:
I´m using Gnuplot via gnuplot.py and I´m 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ¶}¾Ç¤F¶Ü? | last post by:
I'm trying to write a script to pass a file of stock prices and volumes, and plot the results on a gnuplot graph which is non-overlapped graph. Fig. 1 ------------ Fig. 2 Figure 1 is a graph...
4
by: Rama Calaga | last post by:
Hi, I use both python and gnuplot a lot, but I am unable to find a way to embed gnuplot "window/canvas" into tkinter. BLT option in PMW is not so powerful and not so great, any suggestions ?? ...
1
by: Alythh | last post by:
I just installed Chart::Graph::Gnuplot, and I'm fairly satisfied. But... My wish is to be able to make a gnuplot() call, make it display the graph, and stay there while other data becomes...
6
by: Joseph Suprenant | last post by:
Hello all, I have a C++ program, it does some calculations on things and then prints out a file in the format in which GNUPLOT can use. So my question is how would i call GNUPLOT from my C++...
10
by: Sanyi Benczik | last post by:
Is there a standard way in C++ to call an external program or is this platform dependent? If it is platform dependent, can somebody drop a line what to use or where to look for info for GNU C++...
4
by: Alexander Stippler | last post by:
Hello, I want to visualize numerical results with gnuplot. The easiest way would be to use a pipe to gnuplot. But I want to be platform independent, just relying on the C++-standard. What is...
3
by: Bernhard Hidding | last post by:
Hello, my c++ programm produces a variable number of ASCII files with variable file names. These are to be plotted in with gnuplot. I use system("gnuplot -persist my_gnuplot_script.gpl"); to...
5
by: Anton81 | last post by:
Hi, it seems to be a FAQ, but I still haven't found a solution. I want to control gnuplot with a python program. The following at least gives me the gnuplot output: ...
3
by: Peter Beattie | last post by:
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",...
3
by: arslanburney | last post by:
Hello. Was trying to create a simple plotting function. Wasnt working however. If i write the same code without putting it inside a function it works. :S. Could some1 tell me the problem? Heres the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.