%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

"""
Explanation: Matplotlib Exercise 2
Imports
End of explanation
"""


!head -n 30 open_exoplanet_catalogue.txt

"""
Explanation: Exoplanet properties
Over the past few decades, astronomers have discovered thousands of extrasolar planets. The following paper describes the properties of some of these planets.
http://iopscience.iop.org/1402-4896/2008/T130/014001
Your job is to reproduce Figures 2 and 4 from this paper using an up-to-date dataset of extrasolar planets found on this GitHub repo:
https://github.com/OpenExoplanetCatalogue/open_exoplanet_catalogue
A text version of the dataset has already been put into this directory. The top of the file has documentation about each column of data:
End of explanation
"""


# YOUR CODE HERE
#raise NotImplementedError()
data = np.genfromtxt('open_exoplanet_catalogue.txt',comments = '#', delimiter = ',')

assert data.shape==(1993,24)

"""
Explanation: Use np.genfromtxt with a delimiter of ',' to read the data into a NumPy array called data:
End of explanation
"""


# YOUR CODE HERE
#raise NotImplementedError()
#creates array with each entry a tuple
#each tuple consists all the numbers from each column of data
cols = list(zip(*data))
x =[]
#takes out all values of nan in data
#appends non-nan values in mass column to x
for i in range(len(data)):
    nan= not np.isnan(cols[2][i]) 
    if nan:
        x.append(cols[2][i])
plt.hist(x,bins=30, range=(0,15))
plt.xlim(0,15)
plt.title("Planet Mass Distribution")
plt.ylabel('Number of Planets')
plt.xlabel('Mass sin i (Jupiter Masses)')
plt.box(False)
#gives trend line based off trend line in orignonal graph
plt.plot(np.linspace(0.5,15,100),40*np.exp(np.linspace(0.5,15,100)**-1.3)-35)

assert True # leave for grading

"""
Explanation: Make a histogram of the distribution of planetary masses. This will reproduce Figure 2 in the original paper.

Customize your plot to follow Tufte's principles of visualizations.
Customize the box, grid, spines and ticks to match the requirements of this data.
Pick the number of bins for the histogram appropriately.
End of explanation
"""


# YOUR CODE HERE
#raise NotImplementedError()
semi= cols[5]
ecc = cols[6]
plt.scatter(semi,ecc)
plt.ylim(0,1)
plt.xlim(.001, 100)
plt.title('Figure 4')
plt.xscale('log')
plt.xlabel("Semimajor Axis (AU)")
plt.ylabel('Orbital Ecentricity')
plt.box(False)

assert True # leave for grading

"""
Explanation: Make a scatter plot of the orbital eccentricity (y) versus the semimajor axis. This will reproduce Figure 4 of the original paper. Use a log scale on the x axis.

Customize your plot to follow Tufte's principles of visualizations.
Customize the box, grid, spines and ticks to match the requirements of this data.
End of explanation
"""


