我有一个问题。下面是我的代码片段,我试图填充给定函数yv的向量。当我运行代码时,没有错误,但它没有打印出结果,也没有显示我想要的情节。
import matplotlib as plt
import numpy as np
import math as m
e = 2.17
sigma = 1
mu = 0
xv = np.linspace(-4, 4, 100)
for rows in range(0):
for cols in range(100):
yv = 1 / (sigma * (2 * m.pi) ** (-0.5)) * e ** (-0.5) * ((((xv - mu) / sigma)) ** 2)
print('xv= {}'.format(xv))
print('yv= {}'.format(yv))
plt.plot(xv, yv, 'b-o', linewidth = 2, label = 'xv vs. yv')
plt.show()
我错过了什么?
再次感谢! 布兰登
答案 0 :(得分:0)
您的matplotlib导入不太正确。试试这个:
from matplotlib import pyplot as plt
import numpy as np
import math as m
e = 2.17
sigma = 1
mu = 0
xv = np.linspace(-4, 4, 100)
yv = 1/(sigma*(2*m.pi)**(-0.5))*e**(-0.5)*((((xv-mu)/sigma))**2)
print('xv= {}'.format(xv))
print('yv= {}'.format(yv))
plt.plot(xv, yv, 'b-o', linewidth=2, label='xv vs. yv')
plt.show()