#!/usr/bin/python
import numpy as np
import sys
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker

def getFromFile(f):
    data=np.loadtxt(f)
    d=[]
    n=0
    for l in data:
	if l[1]==0:
       	    n+=1	
	    d.append([])
	d[n-1].append(l)
    return d 
def pXRD(ax,i,d,l,c,p,r):
    line,=ax.plot(d[0],vecMinSca(normalize(d[1]),-1*i),label =l, color=c,ls='-',lw=2)
    ax.text(50,i+0.4,l,color=c)
    ax.vlines(p,i,i+1.2,color=c,linestyles='--',lw=1)
    ax.text(p-9,i+0.2,'$'+str(p)+'^{\circ}$',color=c)
#    ax.text(72,i+0.3,'R='+str(r),color=c)
    return line

def save(a,f):
    d=np.transpose(a)
    f = open(f,'w')
    for row in d:
        for line in row:
            f.write(str(line))
            f.write('\t')
        f.write('\n')
    f.close()
        
def normalize(v):
    o=[]
    m=np.amax(v)
    for vr in v:
        o.append(vr/m)
    return o
def vecMinSca(v,s):
    o=[]
    for ve in v:
        o.append(ve-s)
    return o

#Colors
colors = ['g','b','k','darkviolet','c']
labels = ['MAC1000', 'MAC1200', 'MAC1400', 'MAC1600', '5th']
ps=[21.37,21.91,22.64,22.80]
R=[1.975,2.013,2.176,2.304]
# plot
plt.style.use('z') 
d=[] 
for f in sys.argv[1:]:
    d.append(np.loadtxt(f).transpose())


fig=plt.figure()
ax_c = fig.add_subplot(111)


i=0
for data in d:
    
    pXRD(ax_c,i,[data[0],data[1]+data[2]+data[3]+data[4]],labels[i],colors[i],ps[i],R[i])
    i=i+1

ax_c.vlines(43.72,0,4.2,color='k',linestyles='--',lw=1)
ax_c.text(43.72-9,1.8,'$43.72^{\circ}$')
 


ax_c.set_xlim(5,1.1*np.amax(d[0][0]))
ax_c.set_ylim(0,4.2)
ax_c.set_ylabel('Intensity')
ax_c.set_xlabel('$2 \Theta (^{\circ})$')
ax_c.tick_params(labelleft='off')




plt.savefig(f+'.pdf')

e5c39429ce9e7967a42f8e7b0c7744eb00656541
#!/usr/bin/python
import numpy as np
import sys
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker

def getFromFile(f):
    data=np.loadtxt(f)
    d=[]
    n=0
    for l in data:
	if l[1]==0:
       	    n+=1	
	    d.append([])
	d[n-1].append(l)
    return d 
def pXRD(ax,i,d,l,c,p,r):
    line,=ax.plot(d[0],vecMinSca(normalize(d[1]),-1*i),label =l, color=c,ls='-',lw=2)
    ax.text(50,i+0.4,l,color=c)
    ax.vlines(p,i,i+1.2,color=c,linestyles='--',lw=1)
    ax.text(p-9,i+0.2,'$'+str(p)+'^{\circ}$',color=c)
#    ax.text(72,i+0.3,'R='+str(r),color=c)
    return line

def save(a,f):
    d=np.transpose(a)
    f = open(f,'w')
    for row in d:
        for line in row:
            f.write(str(line))
            f.write('\t')
        f.write('\n')
    f.close()
        
def normalize(v):
    o=[]
    m=np.amax(v)
    for vr in v:
        o.append(vr/m)
    return o
def vecMinSca(v,s):
    o=[]
    for ve in v:
        o.append(ve-s)
    return o

#Colors
colors = ['g','b','k','darkviolet','c']
labels = ['MAC1000', 'MAC1200', 'MAC1400', 'MAC1600', '5th']
ps=[21.37,21.91,22.64,22.80]
R=[1.975,2.013,2.176,2.304]
# plot
plt.style.use('z') 
d=[] 
for f in sys.argv[1:]:
    d.append(np.loadtxt(f).transpose())


fig=plt.figure()
ax_c = fig.add_subplot(111)


i=0
for data in d:
    
    pXRD(ax_c,i,[data[0],data[1]+data[2]+data[3]+data[4]],labels[i],colors[i],ps[i],R[i])
    i=i+1

ax_c.vlines(43.72,0,4.2,color='k',linestyles='--',lw=1)
ax_c.text(43.72-9,1.8,'$43.72^{\circ}$')
 


ax_c.set_xlim(5,1.1*np.amax(d[0][0]))
ax_c.set_ylim(0,4.2)
ax_c.set_ylabel('Intensity')
ax_c.set_xlabel('$2 \Theta (^{\circ})$')
ax_c.tick_params(labelleft='off')




plt.savefig(f+'.pdf')
