Gnuplot.py and, _by far_, the weirdest thing I've ever seen on my computer

David M. Cooke cookedm+news at physics.mcmaster.ca
Mon Apr 4 20:27:23 EDT 2005


"syd" <syd.diamond at gmail.com> writes:

> I don't even know where to begin.  This is just bizarre.  I just picked
> up the Gnuplot.py module (a light interface to gnuplot commands) and
> was messing around with it today.
>
> I've got a tiny script, but it only works from the command line about
> half the time!  In the python interpreter, 100%.   Ipython, 100%.  I'm
> not kidding.
>
> #!/bin/env python
> import Gnuplot
> g = Gnuplot.Gnuplot(debug=1)
> g.title('A simple example')
> g('set data style linespoints')
> g('set terminal png small color')
> g('set output "myGraph.png"')
> g.plot([[0,1.1], [1,5.8], [2,3.3], [3,100]])
>
> Here's just one example -- it does not work, then it works.  It seems
> totally random.  It will work a few times, then it won't for a few
> times...
>
> bash-2.05b$ ./myGnu.py
> gnuplot> set title "A simple example"
> gnuplot> set data style linespoints
> gnuplot> set terminal png small color
> gnuplot> set output "myGraph.png"
> gnuplot> plot '/tmp/tmp5LXAow' notitle
>
> gnuplot> plot '/tmp/tmp5LXAow' notitle
>               ^
>          can't read data file "/tmp/tmp5LXAow"
>          line 0: util.c: No such file or directory
>
> bash-2.05b$ ./myGnu.py
> gnuplot> set title "A simple example"
> gnuplot> set data style linespoints
> gnuplot> set terminal png small color
> gnuplot> set output "myGraph.png"
> gnuplot> plot '/tmp/tmpHMTkpL' notitle
>
> (and it makes the graph image just fine)
>
> I mean what the hell is going on?  My permissions on /tmp are wide open
> (drwxrwxrwt).  It does the same thing when I run as root.  And it
> _always_ works when I use the interpreter or interactive python.
>
> Any clues would be greatly appreciated.  I'm baffled.

What's your OS? Python version? Gnuplot.py version (I assume 1.7)?
Put a 'import sys; print sys.version' in there to make sure /bin/env
is using the same python as you expect it to.

It looks like any temporary file it's writing to is deleted too early.

Have a look at gp_unix.py in the Gnuplot source. There's some
customization options that might be helpful. In particular, I'd try

import Gnuplot
Gnuplot.GnuplotOpts.prefer_fifo_data = 0

... then the data will be save to a temporary file instead of piped
through a fifo.

Alternatively, try
Gnuplot.GnuplotOpts.prefer_inline_data = 1

... then no file will be used.

[I don't use Gnuplot myself; this is just what I came up with after a
few minutes of looking at it]

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca



More information about the Python-list mailing list