"""

John Rachlin
DS 2000: Intro to Programming with Data

Filename: kepler.py
    
Description: Verify Kepler's law of planetary motion
    
"""

import matplotlib.pyplot as plt



def main():
    
    with open('kepler.csv', 'r') as infile:
        infile.readline() # Skip header
        data = infile.readlines()  # Read data for all 9 planets
    
    num_planets = len(data)
    distance = []
    period = []
    radius = []
    color = ['brown', 'yellow', 'dodgerblue', 'firebrick', 'coral', 
             'gold', 'teal', 'mediumseagreen', 'black'] 

    # Parse the planet data    
    planet = 0
    while planet < num_planets:
        values = data[planet].split(",")
        
        # Store values: radius, distance^3, period^2
        radius.append(float(values[2])/100)
        distance.append(float(values[3]) ** 3)
        period.append(float(values[4]) ** 2)
        planet = planet + 1
        
    # Generate plot
    plt.figure(figsize=(5,5), dpi=200)
    plt.xlabel('Period [days^2]')
    plt.ylabel('Distance [millions of km ^3]')
    plt.title('Kepler\'s 3rd Law of Planetary Motion')
    plt.scatter(period, distance, s=radius, marker='o', color=color)
    plt.xscale('log')
    plt.yscale('log')
    plt.grid()
    plt.show()


main()




