Join Now
Quality Rating:
  • Currently 4.0 / 5
(4.0 / 5 - 2 votes cast)
Expertise Level:
  • Currently 2.5 / 5
(2.5 / 5 - 2 votes cast)

This page was last modified 23:03, 28 July 2008.

Graphs in python

From Forum Nokia Wiki

Contents

Graphs in Python

The following code generate graphs by very simple inputs by the user. Initially this code is made to draw three graphs. Entire information about the code is given as comment lines.

import e32, appuifw,graphics
 
#title of the application
appuifw.app.title = u"GRAPHS BY CHINTAN"    
 
def quit():
    app_lock.signal()                       
    
def draw():
    
#title of graph 1 assigned to n1. height of graph 1 assigned to x1
    n1 = appuifw.query(u"Title Of Graph 1","text")
    x1 = appuifw.query(u"Enter Height Of Graph 1 (From 1 To 250):","number")
    n2 = appuifw.query(u"Title Of Graph 2","text")
    x2 = appuifw.query(u"Enter Height Of Graph 2 (From 1 To 250):","number")
    n3 = appuifw.query(u"Title Of Graph 3","text")
    x3 = appuifw.query(u"Enter Height Of Graph 3 (From 1 To 250):","number")
 
#In python the height of rectangle will increase as the y co-ordinate of second point decreases.
#since we are using the given height as a coordinate of rectangle
#we have to substract them from 270. this value is the maximum value of y co-ordinate for graph.
    y1 = 270 - x1
    y2 = 270 - x2
    y3 = 270 - x3
    
#the height is converted into string to display it on the top of the graph
    x11 = str(x1)
    x22 = str(x2)
    x33 = str(x3)
        
#defining the canvas    
    canvas = appuifw.Canvas()   
    appuifw.app.body = canvas
 
#this code line clears the canvas with white color.
#the two lines are the x and y axis lines of our graph
    canvas.clear(0xfefefe)              
    canvas.line((40,270,260,270), 0)    
    canvas.line((259,10,259,270), 0)
    
#this five lines will display the unit on the y axis i.e. height of graph
    canvas.text((259,220),u"-50")       
    canvas.text((259,170),u"-100")      
    canvas.text((259,120),u"-150")
    canvas.text((259,70),u"-200")
    canvas.text((259,20),u"-250")
    
#the code will display the height on the top of graph
#the text will always stick to the height 
#whatever it is ranging from 1 to 250
    canvas.text((60,y1-5),u"   %s"%(x11), fill=0xffff00)    
    canvas.text((125,y2-5),u"   %s"%(x22), fill=0x0000ff)   
    canvas.text((190,y3-5),u"   %s"%(x33), fill=0xbe6a0e)   
 
#this code lines shows the name of the graph on x-axis    
    canvas.text((60,285), u" %s"%(n1), fill=0x4b2192)       
    canvas.text((125,285), u" %s"%(n2), fill=0x4b2192)
    canvas.text((190,285), u" %s"%(n3), fill=0x4b2192)
    
#and now finally draw the thing for which the entire application is written i.e. the graphs.
    canvas.rectangle((60,y1,115,270), outline=0xff0000, fill=0xffff00)   
    canvas.rectangle((125,y2,180,270), outline=0xff0000, fill=0x0000ff) 
    canvas.rectangle((190,y3,245,270), outline=0xff0000, fill=0xbe6a0e)
 
draw()
 
#the code will allow the user to exit the application when he presses the exit key
appuifw.app.exit_key_handler=quit  
app_lock=e32.Ao_lock()
app_lock.wait()

Screenshots

The code just looks long but its very easy to understand. Once the graph is drawn a screenshot function can be used to save the image if user wants. Some of the images of the above code are given below.

Graph name:

Image:11.jpeg


Graph size:

Image:12.jpeg


Graph axis:

Image:13.jpeg


Graph:

Image:14.jpeg


some other graphs:

Image:24.jpeg Image:34.jpeg


--Ck.umraliya 18:36, 19 July 2008 (EEST)

Related Discussions
Thread Thread Starter Forum Replies Last Post
Python Script Installer on N80 firebabe Python 8 2006-08-21 06:53
N95 problem resca79 Python 2 2007-07-25 18:32
Where to find basic Python reference? carknue Python 3 2007-06-27 06:07
Where to get "Getting Started with Python for S60 Platform" for the newest Python? timoriensis Python 6 2008-03-28 13:00
Equivalent datetime module? mooninite Python 9 2008-08-03 20:09
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZpythonQ
     qfnZtopicQUqfnTopicZseriesE5f60Q
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX