Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Plotting Graphs using Gnuplot

Reply
Thread Tools

Plotting Graphs using Gnuplot

 
 
arslanburney@gmail.com
Guest
Posts: n/a
 
      06-12-2008
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,] )
 
Reply With Quote
 
 
 
 
Fuzzyman
Guest
Posts: n/a
 
      06-12-2008
On Jun 12, 12:30 pm, (E-Mail Removed) 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,] )


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/
 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      06-12-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) 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,] )
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
 
Reply With Quote
 
Helmut Jarausch
Guest
Posts: n/a
 
      06-13-2008
(E-Mail Removed) 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,] )



--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Plotting multiple datasets with gnuplot Rob Garrett Python 2 10-12-2009 08:00 AM
Plotting Graph Functions using Gnuplot arslanburney@gmail.com Python 1 06-13-2008 04:43 AM
Generating Gnuplot graphs from Perl - and keeping them open ryan Perl Misc 1 05-30-2007 05:17 PM
Creating And Plotting Graphs morc Java 2 02-23-2006 08:22 PM
plotting with gnuplot.py skorpio11@gmail.com Python 4 09-06-2005 02:46 AM



Advertisments