# scatterWineVerySimple.py # Neal Nelson 2008.11.6 import string from graphics import * def main(): # Introduction print "Scatterplot display deaths (y) vs wine consumption (x)" # Read in the whole table tableFile = open("WineConsumption.txt", 'r') table = [] for line in tableFile.readlines(): (country, wine, death) = string.split(line,',') table.append( (float(wine), int(death)) ) tableFile.close() print table # Display a scatter plot xmax = 12.0 ymax = 400 # Create a graphics window with origin in lower left #win = GraphWin("Sample Scatter Plot", 320, 240) win = GraphWin("Sample Scatter Plot", 640, 480) win.setBackground("white") win.setCoords(0.0, 0.0, xmax, ymax) Text(Point(4,10),'Liters Wine Alcohol per Year').draw(win) Text(Point(10,200),'Deaths').draw(win) # Draw the (x,y) points for i in range(0,len(table)): (x,y) = table[i] print (x,y) Point(x,y).draw(win) #Text(Point(x,y),'*').draw(win) # Hold window open #raw_input("Press to quit.") #win.close() # A better click-to-close technique text = Text(Point(xmax/2, ymax-20), 'Click to close') text.draw(win) win.getMouse() win.close() main()