Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import math
- import matplotlib.pyplot as plt
- import matplotlib.animation as animation
- import sys
- #python3 plot_diff.py name_file_IMD name_file_xraydb
- #examples:
- #python3 plot_diff.py Pt_substrate.dat Pt.dat
- #python3 plot_diff.py Pd_substrate.dat Pd.dat
- n = len(sys.argv)
- print("Total arguments passed:", n)
- if n!=3:
- print("2 args needed: name_file_IMD name_file_xraydb")
- else:
- compteur=1
- with open(sys.argv[1]) as ffirst:
- for line in ffirst:
- if compteur==7:
- linestartswithlist = line.strip().split(" ")
- linestartswith = linestartswithlist[0]
- #print(linestartswith)
- compteur+=1
- if line[0]=="#":
- ii = line.strip().split("=")
- if(ii[0]=="#theta_step"):
- theta_step_imd = float(ii[1])
- if(ii[0]=="#theta_min"):
- theta_min_imd = float(ii[1])
- #print(float(theta_min_imd),float(theta_step_imd))
- with open(sys.argv[2]) as fsecond:
- for line in fsecond:
- if line[0]=="#":
- ii = line.strip().split("=")
- if(ii[0]=="#theta_step"):
- theta_step_xraydb = float(ii[1])
- if(ii[0]=="#theta_min"):
- theta_min_xraydb = float(ii[1])
- #print(float(theta_min_xraydb),float(theta_step_xraydb))
- with open(sys.argv[1]) as f:
- lines = (line for line in f if not line.startswith("#") and not line.startswith(linestartswith))
- a=np.loadtxt(lines)
- #print(a)
- sizea=len(a[0])
- Xdeux = np.zeros(sizea)
- Ydeux = np.zeros(sizea)
- i=0
- incr=theta_min_imd
- for elt in a[0]:
- #print(incr,elt)
- Xdeux[i]=incr
- Ydeux[i]=elt
- incr+=theta_step_imd
- i+=1
- with open(sys.argv[2]) as ff:
- lines = (line for line in ff if not line.startswith("#"))
- b=np.loadtxt(lines)
- sizeb=len(b[0])
- Xdeuxb = np.zeros(sizeb)
- Ydeuxb = np.zeros(sizeb)
- i=0
- incr=theta_min_xraydb
- for elt in b[0]:
- #print(incr,elt)
- Xdeuxb[i]=incr
- Ydeuxb[i]=elt
- incr+=theta_step_xraydb
- i+=1
- fig, ax = plt.subplots()
- line, = ax.plot(Xdeux,Ydeux,"r")
- line2, = ax.plot(Xdeuxb,Ydeuxb,"b")
- jj=0
- def animate(i):
- #print(i)
- j=0
- incr=theta_min_imd
- for elt in a[i]:
- #print(incr,elt)
- Xdeux[j]=incr
- Ydeux[j]=elt
- incr+=theta_step_imd
- j+=1
- line.set_ydata(Ydeux) # update the data.
- jj=0
- incr=theta_min_xraydb
- for elt in b[i]:
- #print(incr,elt)
- Xdeuxb[jj]=incr
- Ydeuxb[jj]=elt
- incr+=theta_step_xraydb
- jj+=1
- line2.set_ydata(Ydeuxb)
- return line, line2
- #ani = animation.FuncAnimation(fig, animate, interval=20, blit=True, save_count=50)
- ani = animation.FuncAnimation(fig, animate, frames=200, interval=100, blit=True)
- # To save the animation, use e.g.
- #
- # ani.save("movie.mp4")
- #
- # or
- #
- # writer = animation.FFMpegWriter(
- # fps=15, metadata=dict(artist='Me'), bitrate=1800)
- # ani.save("movie.mp4", writer=writer)
- plt.title(linestartswith)
- plt.xlabel("Theta degree")
- plt.ylabel("Reflectivity")
- plt.legend([line,line2],["IMD","XrayDB"])
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment