Reputation: 55
I have a file abc.dat having data set with column "ec", "ev", "eig", "ep". I have to plot E vs x graph. Here the values for x, E and other variables related to this are given below.
import numpy as np
import matplotlib.pyplot as plt
data = np.loadtxt('/Users/abc.dat')
ec = data[0:,0]
ev = data[0:,1]
eig = data[0:,2]
ep = data[0:,3]
a=(eig-(ec-ev))
A= 5
B=1/eig**2
for x in range(1,500):
g=(1/(0.5* np.sqrt(2*3.14)))* np.exp((-(x-eig)**2)/(2*(0.5)**2))
ep_1=(ep*g)**2
P=sum(ep_1)
for i in a:
if i==0:
D=1
else:
D=0
e=A*B*P*D
plt.plot(x,e)
Upvotes: 0
Views: 120
Reputation: 484
Your code has the plt.plot()
command buried in loops, which is probably not what you are trying to do. You will need x
to be an array the same size as e
, and from your question it might have fewer points than you expect since it has shape (409,).
Try this:
import numpy as np
import matplotlib.pyplot as plt
data = np.loadtxt('/Users/abc.dat')
ec = data[0:,0]
ev = data[0:,1]
eig = data[0:,2]
ep = data[0:,3]
a=(eig-(ec-ev))
A= 5
B=1/eig**2
x = np.arange(len(eig))
g=(1/(0.5* np.sqrt(2*3.14)))* np.exp((-(x-eig)**2)/(2*(0.5)**2))
P=((g*np.broadcast_to(ep, (len(g), len(ep))).T)**2).sum(axis=0)
e=np.where(a==0, A*B*P, 0)
plt.plot(x,e)
I am not sure from the question if I have the logic for P
calculating as you want it to.
Upvotes: 1