In [10]:
import matplotlib.pyplot as plt
import numpy as np
import h5py
import matplotlib as mpl
print(mpl.__version__)
file_loc = "../../build/res.h5"
file = h5py.File(file_loc)
str_0 = "/dset"
from matplotlib import rc
#rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
## for Palatino and other serif fonts use:
#rc('font',**{'family':'serif','serif':['Palatino']})
#rc('text', usetex=True)
#plt.rc('font', family='serif')
#plt.rc('xtick', labelsize=30)
#plt.rc('ytick', labelsize=30)
t = np.linspace(0, 5000, 1000)
x = np.linspace(-30,30,100000)
#T,X = np.meshgrid(t,x,sparse=False,indexing='xy')
pic = np.zeros((100000,1000))
#prob = np.zeros(1000)
dimag = 0
dreal = 0
psi = 0
plt.subplot(211)
print("Working")
for i in range(0, 100000, 100):
ind = i
r_str = str_0 + str(ind) + "real"
i_str =str_0 + str(ind) + "img"
if r_str in file and i_str in file:
dreal = np.array(file[r_str])
dimag = np.array(file[i_str])
psi = dreal**2 + dimag**2
dreal = 0
dimag = 0
else:
print(r_str)
print(i_str)
print("Not found!")
print()
file.close()
exit()
#prob[int(i/100)] = np.trapz(y=psi,x=x)
#print(np.trapz(y=psi,x=x))
pic[:, int(i/100)] = psi
file.close()
print("Plotting!")
a = np.log(2)/(1500-2500)**2
print("a = "+str(a))
b = 0.0069314718056;
t = np.linspace(0, 100, 1e3)
x = np.linspace(-30, 30, 1e3)
t0 = 2500
x0 = 0
g_t = lambda t: np.exp(-a*(t-t0)**2)
g_s = lambda x: np.exp(-b*(x)**2)
plt.imshow(pic,cmap="magma_r",extent=[t[0],t[-1],x[0],x[-1]],aspect='auto',interpolation='nearest')
#plt.plot(t,10*g_t(t)*np.sin(0.08607963870836033*t)-15, color="blue", linewidth=3)
#plt.text(1401,20,r"$g_t(t) \cdot sin(\omega t) \; (arb. \, units)$",fontsize=30,color="blue")
plt.xlabel(r"$t \ (a.u.)$",size=20)
plt.ylabel(r"$x \ (a.u.)$",size=20)
plt.xticks(fontsize=20)
plt.yticks(fontsize=20)
print("Plotting finished!")
c = plt.colorbar()
for t in c.ax.get_yticklabels():
t.set_fontsize(20)
c.set_label(r"Probability density $|\psi_n|^2$",size=20)
print("Colorbar done!")
print("Showing done!")
print("Finished!")
In [11]:
plt.subplot(212)
t = np.linspace(0,100,10000)
x = np.linspace(-30,30,10000)
vals = np.zeros((10000,10000))
w = 1.51939
k = w/137
E0 = 3674.932
inv = 1240.241
t0 = 50
def vu(x,t):
if(t<50):
return t/t0*np.sin(k*x-w*t)
else:
return np.sin(k*x-w*t)
for i in range(0,10000):
vals[:,i] = vu(x,t[i])
plt.imshow(vals,cmap="viridis",extent=[t[0],t[-1],x[0],x[-1]],aspect='auto',interpolation='nearest')
#plt.plot(x,vals[:,5000])
plt.xlabel(r"$t \ (a.u.)$",size=20)
plt.ylabel(r"$x \ (a.u.)$",size=20)
plt.xticks(fontsize=20)
plt.yticks(fontsize=20)
#c = plt.colorbar()
#for t in c.ax.get_yticklabels():
# t.set_fontsize(20)
#c.set_label(r"Disturbance $V_1(x,t) \; (a.u.)$",size=20)
plt.show()
In [12]:
plt.subplot(111)
check = np.zeros(1000)
for i in range(0, 1000):
check[i] = np.trapz(pic[:,i],dx=0.0006)
t = np.linspace(0,100,1000)
plt.plot(t,check)
plt.show()
In [ ]: