
# File: function_linear_01.py
# Programmer: Anne Dawson
# Date: Monday 6th September 2010, 14:37 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


import pylab  # matplotlib


# create the x list data
# arange() is just like range() but allows float numbers
x_list = pylab.arange(-5, 4) # range is -5 to +4 

# calculate the y list data for y = 2x + 3
y_list = []
for x in x_list:
    y = 2 * x + 3
    y_list.append(y)

pylab.title('Linear function f(x) = mx + b:   y = 2x + 3',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.xlim(-10,10)  # this line must be placed AFTER the plot line
pylab.ylim(-10,10) # this line must be placed AFTER the plot line

# save the plot as a PNG image file (optional)
pylab.savefig('function_linear_01.png')
pylab.show()
