# linePlot.py # Neal Nelson 2008.11.17 import string from graphics import * def main(): # Introduction print "Line Plot for fahrenheit = 9.0/5.0 * celsius + 32" # Display a scatter plot (xmin,xmax) = (-20,120) # Celsius range (ymin,ymax) = (-40,300) # Fahrenheit range # Create a graphics window with (xmin,ymin) in lower left #win = GraphWin("Sample Scatter Plot", 320, 240) # small drawing window win = GraphWin("Sample Line Plot", 640, 480) # bigger drawing window win.setBackground("white") win.setCoords(xmin, ymin, xmax, ymax) # Draw x-axis and y-axis Line(Point(xmin,0), Point(xmax,0)).draw(win) # x-axis Line(Point(0,ymin), Point(0,ymax)).draw(win) # y-axis # Draw labels on axes Text(Point(50,-8),'Celsius').draw(win) Text(Point(10,200),'Fahrenheit').draw(win) # Draw the (x,y) points for i in range(xmin,xmax+1): celsius = float(i) fahrenheit = 9.0/5.0 * celsius + 32 print celsius,fahrenheit # for debugging Point(celsius,fahrenheit).draw(win) # Hold window open #raw_input("Press to quit.") #win.close() # A better click-to-close technique text = Text(Point(xmax/2, ymin+5), 'Click to close') text.draw(win) win.getMouse() win.close() main()