import  matplotlib.pyplot as plt
import numpy as np



name="indolewater"
tag ="Indole."+r'$H_{2}O$'
fit=np.loadtxt(name+"_mcmc_sampling.res") #Fitting results 
data=np.loadtxt("indolewater.dat") #Experimental dataset
#theo = np.loadtxt("dataset_tr=050_fs_tcc=005_fs_theor.dat") #theoretical
print(np.shape(data))

fig = plt.figure()
#final average fit
plt.plot(fit[:,0],fit[:,1],'k',linewidth=2,label = 'Fit')  
plt.plot(fit[:,0],fit[:,4]+fit[:,8],'k',linewidth=2,label = 'Fit peak1')   
plt.plot(fit[:,0],fit[:,4]+fit[:,10],'k',linewidth=2,label = 'Fit peak2') 
plt.plot(fit[:,0],fit[:,4]+fit[:,6],'k',linewidth=2,label = 'Step up')                  
#plt.fill_between(fit[:,0],fit[:,1]-fit[:,2],fit[:,1]+fit[:,2],facecolor='k',alpha =0.5)

#Experimental data
plt.errorbar(data[:,0],data[:,1],yerr=data[:,2],fmt='og',ms=2,ecolor = '#3f9b0b',label = 'Generated dataset '+str(tag))
#theoretical data
#plt.plot(theo[:,0],theo[:,1],'red',linewidth=2,label = 'Theoretical')         


#plt.ylim(-0.5,1.5)
#plt.xlim(-2,2)
#plt.xticks(np.arange(-1.5, 2.5,1),fontsize = '18')
#plt.yticks(np.arange(0.6, 2.3,0.4),fontsize = '18')
plt.xlabel("Pump-probe delay (ps)",fontsize='18')
plt.ylabel("Ion yield",fontsize='18')
#plt.title("C$_{13}$H$_{x}^{+}$",fontsize='20')
plt.legend(loc='upper right',fontsize = '12') #12 font size is okay here.
#plt.axvline(x=t0,ls='--')
plt.savefig(name+'.svg', dpi=500, facecolor='w', edgecolor='w',
        orientation='portrait', papertype=None, format=None,
        transparent=True, bbox_inches='tight', pad_inches=0.1,
        frameon=None, metadata=None)

plt.savefig(name+'.pdf', dpi=500, facecolor='w', edgecolor='w',
        orientation='portrait', papertype=None, format=None,
        transparent=True, bbox_inches='tight', pad_inches=0.1,
        frameon=None, metadata=None)



plt.show()

t0=np.loadtxt("variable_t0_sampled_distribution.res")
tcc=np.loadtxt("variable_tcc_sampled_distribution.res")
tr=np.loadtxt("variable_tr_sampled_distribution.res")
fig, ax = plt.subplots(1,3, figsize=(10,4))
ax[0].bar(t0[:,0],t0[:,1],width=t0[5,0]-t0[4,0],fc=None,fill=0)
ax[1].bar(tcc[:,0],tcc[:,1],width=tcc[5,0]-tcc[4,0],fc=None,fill=0)
ax[2].bar(tr[:,0],tr[:,1],width=tr[5,0]-tr[4,0],fc=None,fill=0)
ax[0].set_xlabel("t0")
ax[0].set_ylabel("Distibution")

ax[1].set_xlabel(r'$\tau_{cc}$')
#ax[1].set_ylabel("Distibution")

ax[2].set_xlabel(r'$\tau_{r}$')
#ax[2].set_ylabel("Distibution")

plt.suptitle("Variable distribution \n"+str(tag)) 
plt.savefig(name+"Variable_distribution.png")


plt.show()