Plotting Graphs using Gnuplot
__peter__ at web.de
Thu Jun 12 16:03:39 CEST 2008
arslanburney at gmail.com wrote:
> 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?
Judging from the demo you have to keep a Gnuplot.Gnuplot instance alive. If
you don't, the display window is immediately garbage-collected.
> Heres the code:
> # File name Plotting2
> import Gnuplot
> def plot(original, expected, actual):
> if type (original) != type():
> return False
> gp = Gnuplot.Gnuplot()
> gp('set data style lines')
> # Make the plot items
> plot1 = Gnuplot.PlotItems.Data(original, title="Original")
> plot2 = Gnuplot.PlotItems.Data(expected, title="Expected")
> plot3 = Gnuplot.PlotItems.Data(actual, title="Acutal")
gp.plot(plot1, plot2, plot3)
> import Plotting2 #The name of my file...
gp = Plotting2.plot( [(2,3), (3,4)], [(4,5), (5,6)], [(1,3), (4,8)] )
By the way, I recommend that you raise an Exception instead of returning a
special value when plot() cannot deal with the arguments passed to it.
More information about the Python-list