# coding=utf-8
import numpy as np
import matplotlib.ticker as ticker
import matplotlib.pyplot as plt
import pandas as pd
one_au=149597870.700
G = 6.67408e-11
from math import pi

filename = 'planets.dat'
labels = ['Planet', 'Große Halbachse', 'Umlaufzeit','Zentralmasse']
planets = pd.read_csv(filename,skiprows=1,delim_whitespace=True,usecols=(0,1,2,3),names=labels)

filename = 'planets_kepler.dat'
labels = ['Planet', 'Große Halbachse', 'Umlaufzeit','Zentralmasse']
planets_kepler = pd.read_csv(filename,skiprows=1,delim_whitespace=True,usecols=(0,1,2,3),names=labels)

print planets_kepler

fig, ax = plt.subplots()
ax.plot(planets_kepler['Große Halbachse'],planets_kepler['Umlaufzeit'],'or',label='Daten von Kepler',ms=12)
for i, txt in enumerate(planets_kepler['Planet']):
    ax.annotate(txt, (planets_kepler['Große Halbachse'][i], planets_kepler['Umlaufzeit'][i]),fontsize=18)
ax.set_xlabel(u'Große Halbachse [AE]',fontsize=16)
ax.set_ylabel('Umlaufzeit [Tage]',fontsize=16)
ax.set_yscale('log')
ax.set_xscale('log')
ax.set_xlim(3.e-1,30.)
ax.set_ylim(50,40000.)
plt.grid(True,which='both',ls='--',color='grey')
plt.savefig('planets_kepler.eps',bbox_inches='tight',dpi=150)
plt.show()

fig, ax = plt.subplots()
ax.plot(planets_kepler['Große Halbachse'],planets_kepler['Umlaufzeit'],'or',label='Daten von Kepler',ms=12)
ax.plot(planets['Große Halbachse'],planets['Umlaufzeit'],'ok',label='Heutige Daten')
for i, txt in enumerate(planets['Planet']):
    ax.annotate(txt, (planets['Große Halbachse'][i], planets['Umlaufzeit'][i]),fontsize=18)
ax.set_xlabel(u'Große Halbachse [AE]',fontsize=16)
ax.set_ylabel('Umlaufzeit [Tage]',fontsize=16)
ax.set_yscale('log')
ax.set_xscale('log')
plt.grid(True,which='both',ls='--',color='grey')
ax.set_xlim(3.e-1,100.)
ax.set_ylim(50,500000.)
plt.savefig('planets_all.eps',bbox_inches='tight',dpi=150)
plt.show()

filename = 'moons.dat'
labels = ['Mond', 'Große Halbachse', 'Umlaufzeit','Zentralmasse']
moons = pd.read_csv(filename,skiprows=1,delim_whitespace=True,usecols=(0,1,2,3),names=labels)

fig, ax = plt.subplots()
ax.plot(planets_kepler['Große Halbachse']**3*4*pi**2/(G*planets_kepler['Zentralmasse'])*one_au**3,planets_kepler['Umlaufzeit']**2,'or',ms=12,label='Keplers Planeten')
ax.plot(planets['Große Halbachse']**3*4*pi**2/(G*planets['Zentralmasse'])*one_au**3,planets['Umlaufzeit']**2,'ok',label='Planeten')
ax.plot(moons['Große Halbachse']**3*4*pi**2/(G*moons['Zentralmasse']),moons['Umlaufzeit']**2,'ob',label='Monde')
ax.set_xlabel(u'Große Halbachse$\mathregular{^3 x 4 \pi^2/G M}$ [km$\mathregular{^3}$/kg/s$\mathregular{^2}$]',fontsize=16)
#for i, txt in enumerate(planets['Planet']):
#    ax.annotate(txt, (planets['Große Halbachse'][i]**3*4*pi**2/(G*planets['Zentralmasse'])*one_au**3, planets['Umlaufzeit'][i]**2),fontsize=16)
ax.set_ylabel(u'Umlaufzeit$\mathregular{^2}$ [Tage$\mathregular{^2}$]',fontsize=16)
ax.set_yscale('log')
ax.set_xscale('log')
ax.set_ylim(5.e-2,5.e11)
ax.set_xlim(1.e-1,1.e12)
ax.legend(fontsize='large',loc='upper left')
#for i, txt in enumerate(planets['Planet']):
#    ax.annotate(txt, (planets['Große Halbachse'][i]**3*4*pi**2/(G*moons['Zentralmasse']), planets['Umlaufzeit'][i]**2),fontsize=16)
#for i, txt in enumerate(moons['Mond']):
#    ax.annotate(txt, (moons['Große Halbachse'][i]**3*4*pi**2/(G*moons['Zentralmasse']), moons['Umlaufzeit'][i]**2),fontsize=16)
plt.grid(True,which='both',ls='--',color='grey')
plt.savefig('planets_and_moons.eps',bbox_inches='tight',dpi=150)
plt.show()

