473,471 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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
3 6170
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: rhmd | last post by:
I need to create image files (eg bmp or jpeg) of xy scatter graphs (i.e., graphs in which markers denote individual points; the markers need to be small polygons of various sizes, shapes, colors,...
6
by: Gerrit Holl | last post by:
Hi, I have a dictionairy containing DateTime objects as keys and integers as values. What would be the easiest way to create a simple plot of these, with a number axis versus a time axis? What...
9
by: Dr. Colombes | last post by:
What is the easiest way to generate some plots and graphs in Python ? Specifically interested in simple histograms and scatter plots with circles and regression lines. Thanks for your...
4
by: skorpio11 | last post by:
Hi, I've been having some problems trying some basic plotting commands with gnuplot.py. My setup is the Python 2.3 Enthought edition and my script looks as: from scipy import * from scipy...
8
by: Freddy | last post by:
Hi guys, I have a quick question, I have a program that generates numerical output (as most of the programs), the program is written in C language, and currently I use the "DOS interface to...
1
by: wayne | last post by:
i want to plot a line graph. The values that I obtain are the RGB value of a TIFF image. i m plotting RGB values vs value(1,2,3..) so when generated the RGB values, there will b a column of values...
7
by: diffuser78 | last post by:
My python program spits lot of data. I take that data and plot graphs using OfficeOrg spredsheet. I want to automate this task as this takes so much of time. I have some questions. 1. Which is...
0
by: robert | last post by:
What is a good library for plotting graphs to (compressed) gif / jpg images? Has anybody experience with this? I want to put some simple 2D (and maybe 3D) graph data visualization on a web...
7
by: arslanburney | last post by:
Hello. Ive got two functions here. Somehow the program does not go in to the second function wehn i call it. The bestfit function. Could some1 help me identify the problem. Heres the code: ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.