from __future__ import division
import numpy as np
from numpy import pi
import matplotlib.pyplot as plt
import matplotlib
from matplotlib import ticker
import matplotlib.gridspec as gridspec
from scipy.optimize import curve_fit
import os,sys
plt.rc('text', usetex=True)
plt.rc('font', family='serif',serif='Times',size=44)

nmax1=np.loadtxt('data/nmax1.txt')
nmax2=np.loadtxt('data/nmax2.txt')
nfinal1=np.loadtxt('data/nfinal1.txt')
nfinal2=np.loadtxt('data/nfinal2.txt')
gs=np.loadtxt('data/gs.txt')
Ts=np.loadtxt('data/Ts.txt')

nmax1h=np.loadtxt('datah/nmax1.txt')
nmax2h=np.loadtxt('datah/nmax2.txt')
nfinal1h=np.loadtxt('datah/nfinal1.txt')
nfinal2h=np.loadtxt('datah/nfinal2.txt')
gsh=np.loadtxt('datah/gs.txt')
Tsh=np.loadtxt('datah/Ts.txt')

ng,M=np.shape(nmax1)
M=M+1

def exc_degree(nmax_j):
    nmax_j_bc=nmax_j[:int(M*5/12)]
    nmax_j_ac=nmax_j[int(M*7/12):]
    return (np.max(nmax_j_bc)-np.min(nmax_j_bc))/(np.max(nmax_j_bc)+np.min(nmax_j_bc)),(np.max(nmax_j_ac)-np.min(nmax_j_ac))/(np.max(nmax_j_ac)+np.min(nmax_j_ac)),np.average(nmax_j_bc),np.average(nmax_j_ac)

fsize=(20,14)
fontsizela=60
figc=plt.figure(figsize=fsize)
spec=gridspec.GridSpec(ncols=3,nrows=2,width_ratios=[5,1,5])
exc_1,exc_2,exc_1h,exc_2h=np.zeros((ng,4)),np.zeros((ng,4)),np.zeros((ng,4)),np.zeros((ng,4))
for j in range(ng):
    exc_1[j,:]=exc_degree(nmax1[j,:])
    exc_2[j,:]=exc_degree(nmax2[j,:])
    exc_1h[j,:]=exc_degree(nmax1h[j,:])
    exc_2h[j,:]=exc_degree(nmax2h[j,:])
ax1c=figc.add_subplot(spec[0,0])
ax2c=figc.add_subplot(spec[0,2])
ax3c=figc.add_subplot(spec[1,0])
ax4c=figc.add_subplot(spec[1,2])
ax1c.scatter(gs,exc_1[:,1])
ax2c.scatter(gs,exc_2[:,1])
ax3c.scatter(gs,exc_1h[:,1])
ax4c.scatter(gs,exc_2h[:,1])
ax3c.set_xlabel('$g$',fontsize=fontsizela,labelpad=-10)
ax4c.set_xlabel('$g$',fontsize=fontsizela,labelpad=-10)
ax1c.set_ylabel('$\\eta_{1}$',rotation=0)
ax2c.set_ylabel('$\\eta_{2}$',rotation=0)
ax3c.set_ylabel('$\\eta_{1}$',rotation=0)
ax4c.set_ylabel('$\\eta_{2}$',rotation=0)
ax1c.yaxis.set_label_coords(-0.3,0.45)
ax2c.yaxis.set_label_coords(-0.35,0.45)
ax3c.yaxis.set_label_coords(-0.3,0.45)
ax4c.yaxis.set_label_coords(-0.35,0.45)
ax1c.set_ylim(ymin=0,ymax=0.16)
ax2c.set_ylim(ymin=0,ymax=0.02)
ax3c.set_ylim(ymin=0,ymax=0.16)
ax4c.set_ylim(ymin=0,ymax=0.02)
plt.savefig('fig9.eps',pad_inches=0)
