
# File: function_linear_02.py
# Programmer: Anne Dawson
# Date: Monday 6th September 2010, 15:51 PT
# Python Version: 2.6
# OS: Windows XP
# Textbook: Precalculus - Functions and Graphs, Swokowski & Cole, 11e
# Sketching the graph of a linear function
# Page: 146/147


import pylab  # matplotlib


# create the x list data
# arange() is just like range() but allows float numbers
x_list = pylab.arange(-8, 8) # range is -8 to +8 

# calculate the y list data for y = -1/4 * x + 9/2
y_list = []
for x in x_list:
    y = -1.0/4 * x + 9.0/2
    y_list.append(y)

pylab.title('Linear function f(x) = mx + b:   y = -1/4 * x + 9/2',fontsize=13, color='black')
pylab.xlabel("x",fontsize=18, color='black')
pylab.ylabel("y",fontsize=18, color='black')
pylab.grid(True)
pylab.axhline(0, color='black', lw=2) # axis horizontal line at y = 0, line width 2
pylab.axvline(0, color='k', lw=2) # axis vertical line at x = 0, line width 2, color black
pylab.plot(x_list, y_list, 'b') # plot with a blue line
pylab.plot(-2,5, 'ko') # plot point -2,5  with black dot
pylab.plot(6,3, 'ko') # plot point 6,3 with black dot
pylab.xlim(-8,8)  # this line must be placed AFTER the plot line
pylab.ylim(-2,8) # this line must be placed AFTER the plot line

# save the plot as a PNG image file (optional)
pylab.savefig('function_linear_02.png')
pylab.show()
