
# File: intersection_points_01.py
# Programmer: Anne Dawson
# Date: Sunday 22nd August 2010, 13:38 PT
# Python Version: 2.6
# OS: Windows 7
# Textbook: Precalculus - Functions and Graphs, Swokowski & Cole, 11e
# Page: 113

# Plots a parabola and a straight line intersectiong at two points
# parabola: y = x^2 -3,  line: y = 2x -1


import pylab  # matplotlib


# create the x list data
# arange() is just like range() but allows float numbers
x_list = pylab.arange(-10, 10, 0.0005) # range is -10 to +10 in steps 0.0005

# calculate the y1 list data for parabola: y = x^2 - 3
y1_list = []
for x in x_list:
    y = x**2 - 3
    y1_list.append(y)

# calculate the y2 list data for line y = 2x - 1
y2_list = []
for x in x_list:
    y =  2 * x - 1 
    y2_list.append(y)
 
pylab.title('Intersection points of two graphs',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, y1_list, 'b') # plot with a blue line
pylab.plot(x_list, y2_list, 'r') # plot with a red line

pylab.xlim(-8,8)  # this line must be placed AFTER the plot line
pylab.ylim(-12,12) # this line must be placed AFTER the plot line

# save the plot as a PNG image file (optional)
pylab.savefig('intersection_points_01.png')
pylab.show()
