1

I've a python script who generate a graphic with gnuplot. But I've an error:

gnuplot> plot ^ line 0: function to plot expected

    g=Gnuplot.Gnuplot(persist=1)
    g.title('Read&Write Performance')
    g.xlabel('minutes')
    g.ylabel('MB/s')
    g('set term png')
    g('set out')
    g('set yrange [0:70]')
    d1=Gnuplot.Data(self.time,self.list1,title="perfr", with_="line")
    d2=Gnuplot.Data(self.time,self.list2,title="perfw", with_="line")
    time.sleep(2)
    g.hardcopy('bench.png',terminal = 'png')
    g.reset()

self.list1= [12, 15, 17] self.list2 = [43, 48, 49]

I don't understand why I've this error.

Thanks :)

4
  • Are you talking about Gnuplot.py? I haven't used it much - but calling time.sleep looks a little suspect. Is there a way of seeing the code that gets sent to gnuplot? It might be easier to see what is wrong with that. Also, it looks like this project hasn't been updated for quite a long time - it is conceivable that it isn't compatible with recent versions of gnuplot. You might find it easier to use matplotlib instead. Commented Apr 9, 2012 at 11:03
  • I've read that time.sleep, helps gnuplot to fully execute the commands. Commented Apr 9, 2012 at 11:38
  • It doesn't seem like you're actually sending the data to be plotted anywhere. A quick perusal of test.py makes me think that you should have a line in there like... g.plot(d1) ... If you want them to show up together, I don't know how it works ... Commented Apr 9, 2012 at 12:24
  • @mgilson I don't want a gnuplot windows. Only save graphic as png file. g.plot() show gnuplot windows Commented Apr 9, 2012 at 15:00

1 Answer 1

2

After a very brief look at the source, it seems that g.plot() does not send the plot to a window (e.g. x11), but to wherever gnuplot is currently configured to send the plot. So, (I think) the easiest solution is --

g('set terminal png')
g('set output "bench.png"')
g.plot(d1)  #d1 should not be in "bench.png"
#This might work to plot both datasets together ... g.plot(d1,d2)  

This should work as long as the internals of gnuplot-py don't reset the gnuplot script whenever a plot command is issued. I highly doubt this is the case since the __call__ method seems to be such an important part of the API.

Sign up to request clarification or add additional context in comments.

1 Comment

You are right mgilson! It's simply perfect. It's works fine. Thanks a lot :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.