# -*- coding: utf-8 -*-

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colorbar as clb
import matplotlib.patches as mpatches
import matplotlib.lines as mlines
from matplotlib.ticker import LogLocator

p_alpha = 1
fig = plt.figure(figsize=(16, 12))

#ax = plt.subplot(111)
ax1 = plt.subplot(2,1,1)
ax2 = plt.subplot(2,1,2)

#ax = fig.add_subplot(111)
#ax1 = fig.add_subplot(211)
#ax2 = fig.add_subplot(212)

comp = []
comp = np.loadtxt('2008B/YStress.dat',delimiter=',')
ref = []
ref = np.loadtxt('2008B/2008_Effects_Booth_r.dat')
comp2 = []
comp2 = np.loadtxt('2008S/YStress.dat',delimiter=',')
ref2 = []
ref2 = np.loadtxt('2008S/2008_Effects_sudbrack_r.dat')
comp3 = []
comp3 = np.loadtxt('2010B/YStress.dat',delimiter=',')
ref3 = []
ref3 = np.loadtxt('2010B/2010_on_Booth_r.dat')

#ax.errorbar(ref[:,0], ref[:,1], yerr=ref[:,2], s=150, marker='o', c='r',zorder=3)
ax2.errorbar(ref[:,0], ref[:,1], yerr=ref[:,2], fmt='o', c='r',markersize=15, lw=3, label='Kt1')
ax2.plot(comp[:,0],comp[:,2],c='r',lw=3)
ax1.errorbar(ref2[:,0], ref2[:,1], yerr=ref2[:,2], fmt='o', c='b',markersize=15, lw=3, label='Kt2')
ax1.plot(comp2[:,0],comp2[:,2],c='b',lw=3)
ax2.errorbar(ref3[:,0], ref3[:,1], yerr=ref3[:,2], fmt='o', c='g',markersize=15, lw=3, label='Kt3')
ax2.plot(comp3[:,0],comp3[:,2],c='g',lw=3)


# Turn off axis lines and ticks of the big subplot
#ax.spines['top'].set_color('none')
#ax.spines['bottom'].set_color('none')
#ax.spines['left'].set_color('none')
#ax.spines['right'].set_color('none')
#ax.tick_params(labelcolor='none', top='off', bottom='off', left='off', right='off')

#ax2.set_xlabel(u'$t$, min', fontsize=45, labelpad=15)
#ax.set_ylabel(r'$\bar{R}^{\gamma^{\prime}}$, nm', fontsize=45)

ax1.tick_params(axis='x', labelsize=30, pad = 10)
ax1.tick_params(axis='y', labelsize=30, pad = 10)
ax2.tick_params(axis='x', labelsize=30, pad = 10)
ax2.tick_params(axis='y', labelsize=30, pad = 10)

ax1.set_xscale("log", nonposx='clip')
ax2.set_xscale("log", nonposx='clip')
ax1.set_xlim(0.01, 8E5)
ax2.set_xlim(5, 8E5)
ax1.set_ylim(0, 200)
ax2.set_ylim(0, 25)

ax1.locator_params(axis = 'y', nbins = 3)
ax2.locator_params(axis = 'y', nbins = 4)
ax1.xaxis.set_major_locator(LogLocator(base = 1E2))
ax2.xaxis.set_major_locator(LogLocator(base = 1E2))


handles, labels = ax1.get_legend_handles_labels()
ax1.legend(handles, labels, loc='upper left',numpoints=1, prop={'size':35})

handles, labels = ax2.get_legend_handles_labels()
ax2.legend(handles, labels, loc='upper left',numpoints=1, prop={'size':35})

fig.subplots_adjust(hspace=.3)

#ax.grid(True)
#fig.tight_layout()

fig.text(0.55, 0.04, u'$t$, min', ha='center', va='center', fontsize=45)
fig.text(0.04, 0.55, r'$\bar{R}^{\gamma^{\prime}}$, nm', fontsize=45, ha='center', va='center', rotation='vertical')


plt.subplots_adjust(top=0.95,bottom=0.13,right=0.96,left=0.13)


plt.show()

