Hi
The pseudo code representing my code is as follows:
def plot(gnuCommands, data, fileID)
#gnuCommands is an array of strings
#data is a 2D numpy array with data[0]
#giving the x-axis and data[1] giving the
#y-values over the x-axis for some function
g = Gnuplot.Gnuplot()
fileName = getFileName(fileID)
for command in gnuCommands:
g(command)
g('set terminal postscript enhance color')
g('set output "fileName"')
g.plot(data[0],data[1])
g.close()
def foo(args):
#args is an array of 2D numpy arrays
gnuCommands = getCommands()
for arg in args:
plot(gnuCommands, arg, getFileID())
The result of this is that the last call to plot produces a correct
plot. All preceding calls produce an empty plot. The only fix I've found
is to initialise g in foo and pass it to plot. Thus I'm assuming that my
problem is due to something like the temporary files for each g.plot()
call being removed when a new Gnuplot.Gnuplot object is instantiated.
Am I right?
I'd like to keep the initialisation of Gnuplot.Gnuplot within the plot
method (in my case the plot method is in a different class and I'd
prefer not to include needless requirements for initialisation on other
classes that use this method).
What steps can I take to fix this? E.g. if the temporary file thing is
the problem is there a way to make them permanent? (It's not a bad thing
in my case to have the data output in such a way).
Cheers,
Ben
|