
# File: semicircle01.py
# Programmer: Anne Dawson
# Date: Sunday 22nd August 2010, 10:53 PT
# Python Version: 2.6
# OS: Windows 7
# Textbook: Precalculus - Functions and Graphs, Swokowski & Cole, 11e
# Page: 111


import pylab  # matplotlib


# create the x list data
# arange() is just like range() but allows float numbers
x_list = pylab.arange(-9, 10, 0.1) # range is -9 to +9 in steps 0.1

# calculate the y1 list data for y = plus sqrt(81 - x^2)
y1_list = []
for x in x_list:
    y = pylab.sqrt(81 - x**2)
    y1_list.append(y)

# calculate the y2 list data for y =  minus sqrt(x)
y2_list = []
for x in x_list:
    y = -1 * pylab.sqrt(81 - x**2)
    y2_list.append(y)
 

pylab.title('Semicircles: y = +/- square root of 81 - x squared',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(-12,12)  # 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('semicircle01.png')
pylab.show()
