467,080 Members | 927 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,080 developers. It's quick & easy.

Plotting Graphs using Gnuplot

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 code:
# File name Plotting2

import Gnuplot

def plot(original, expected, actual):
if type (original) != type([]):
return False

else:

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")
return gp.plot(plot1, plot2, plot3)
----

import Plotting2 #The name of my file...

Plotting2.plot( [(2,3), (3,4)], [(4,5), (5,6)], [(1,3), (4,8)] )
Jun 27 '08 #1
  • viewed: 5931
Share:
3 Replies
On Jun 12, 12:30 pm, arslanbur...@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? Heres the code:

# File name Plotting2

import Gnuplot

def plot(original, expected, actual):

if type (original) != type([]):
return False

else:

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")

return gp.plot(plot1, plot2, plot3)

----

import Plotting2 #The name of my file...

Plotting2.plot( [(2,3), (3,4)], [(4,5), (5,6)], [(1,3), (4,8)] )
I've no idea about the answer to your question (I don't know how the
Gnuplot module works and I can't *see* anything obviously wrong with
your code), but this line:

if type (original) != type([])

is better written:

if not isinstance(original, list):

Michael Foord
http://www.ironpythoninaction.com/
Jun 27 '08 #2
ar**********@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

else:

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)
return gp
>

----

import Plotting2 #The name of my file...
gp = Plotting2.plot( [(2,3), (3,4)], [(4,5), (5,6)], [(1,3), (4,8)] )
raw_input()

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.

Peter
Jun 27 '08 #3
ar**********@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? Heres the code:
# File name Plotting2

import Gnuplot

def plot(original, expected, actual):
if type (original) != type([]):
return False

else:

gp = Gnuplot.Gnuplot()
Replace this by (from
http://wiki.aims.ac.za/mediawiki/ind...Gnuplot_module
)
gp = Gnuplot.Gnuplot(persist=1)
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")
return gp.plot(plot1, plot2, plot3)
----

import Plotting2 #The name of my file...

Plotting2.plot( [(2,3), (3,4)], [(4,5), (5,6)], [(1,3), (4,8)] )

--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Gerrit Holl | last post: by
9 posts views Thread by Dr. Colombes | last post: by
4 posts views Thread by skorpio11@gmail.com | last post: by
8 posts views Thread by Freddy | last post: by
1 post views Thread by wayne | last post: by
7 posts views Thread by diffuser78@gmail.com | last post: by
reply views Thread by robert | last post: by
7 posts views Thread by arslanburney@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.