%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
"""


data = np.genfromtxt(fname = 'open_exoplanet_catalogue.txt', delimiter = ',')

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


data[np.isnan(data)] = 0

assert data.shape==(1993,24)

"""
Explanation: Looked this up on stackoverflow to replace nans in array with zeros
End of explanation
"""


fig = plt.figure(figsize=(7,7))
plt.hist(x=data[::1,2], bins = 1500)
plt.title('Planetary Masses Histogram')
plt.tick_params(top=False, right=False)
plt.xlabel('Planetary Mass(Jupiter Mass)')
plt.ylabel('Number of Planets')
plt.ylim(0,80)
plt.xlim(0,270)
plt.tick_params(axis='both', direction = 'out')

a = []
b = []
c = []
for x in data[::1,2]:
    if x > 0 and x < 1:
        a.append(x)
    elif x > 1 and x < 12:
        b.append(x)
    elif x > 12:
        c.append(x)

fig = plt.figure(figsize=(10,7))
plt.subplot(1,3,1)
plt.hist(a)
plt.ylabel('Number of Planets')
plt.xlabel('Planetary Mass(Jupiter Mass)')
plt.tick_params(top=False, right=False)
plt.tick_params(axis='both', direction = 'out')

plt.subplot(1,3,2)
plt.hist(b)
plt.title('Planetary Masses Histogram')
plt.xlabel('Planetary Mass(Jupiter Mass)')
plt.tick_params(top=False, right=False)
plt.tick_params(axis='both', direction = 'out')

plt.subplot(1,3,3)
plt.hist(c)
plt.xlabel('Planetary Mass(Jupiter Mass)')
plt.tick_params(top=False, right=False)
plt.tick_params(axis='both', direction = 'out')

plt.tight_layout()

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
"""


fig= plt.figure(figsize=(8,5))
plt.scatter(data[::1,5], data[::1,6], marker = '.')
plt.title('Scatter Plot of Obrbital Eccentricity vs. Semimajor Axis')
plt.tick_params(right=False, top=False)
plt.ylabel('Orbital Eccentricity')
plt.xlabel('Semimajor Axis')
#plt.semilogx()
plt.xlim(0,2)
plt.ylim(-.01,1)
plt.tick_params(axis='both', direction = 'out')

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
"""


