Graphing Code

Below is the finalized code for the creation of the graph to be posted on www.acad.ece.udel.edu/~ritter. Descriptions of the code can be found at my blog.

 
import matplotlib.pyplot as plt
 
import os,stat,string
 
 
 
# Dining Sensors Project Graphing Code
 
# It takes in a file and parses the file down into a series of numbers which
 
#    are then used to graph a line plot over all the points.
 
 
 
# Loop until Ready to graph
 
bOld= os.path.getsize('Numbers.txt')
 
i=0
 
while i<20:
 
    bNew= os.path.getsize('Numbers.txt')
 
    if bOld < bNew:
 
        i= i+1
 
        print('Numbers.txt File Updated '+str(i) + ' times. Size:' + str(bNew))
 
	bOld=bNew
 
# Open the File
 
 
 
try:
 
    filename = 'Numbers.txt'
 
    file = open(filename, 'r')
 
except IOError:
 
    print 'Cannot open file %s for reading' % filename
 
    import sys
 
    sys.exit(0)
 
 
 
# Parsing the File to create an Array of Data for Graphing
 
 
 
for line in file:
 
    Data= map(int, string.strip(line).split("  "))
 
    print Data
 
 
 
file.close()
 
 
 
# Graphing the File
 
 
 
Time = range(5,len(Data)*5+1,5)
 
 
 
fig = plt.figure()
 
ax = fig.add_subplot(1,1,1)
 
ax.yaxis.grid(color='gray', linestyle='dashed')
 
ax.xaxis.grid(color='gray', linestyle='dashed')
 
plt.plot(Time,Data,marker='.')
 
plt.xlabel('Time (minutes)')
 
plt.ylabel('# of People')
 
plt.title('Dining Hall Sensor Project')
 
plt.savefig('/usa/ritter/public_html/Test.png')
 
os.chmod('/usa/ritter/public_html/Test.png',stat.S_IROTH|stat.S_IWUSR)
 
Back to top
projects/hallsensor/graphing_code.txt · Last modified: 2010/01/31 16:54 by billiardsace
 
 
chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0