python中的绘图问题
当我运行代码时,绘图仅显示在点x=4处。我希望它能在整个间歇期内出现python中的绘图问题,python,matplotlib,Python,Matplotlib,当我运行代码时,绘图仅显示在点x=4处。我希望它能在整个间歇期内出现 from math import exp, pi, sin import matplotlib.pyplot as plt for x in range(-4,5): f = (exp(-1*(x)**2))*sin(3*pi*(x)) print(x,"\t", f) plt.plot(x,f, 'ro', markersize=1) plt.show() 必须在列表中累积值才能绘制它们: from mat
from math import exp, pi, sin
import matplotlib.pyplot as plt
for x in range(-4,5):
f = (exp(-1*(x)**2))*sin(3*pi*(x))
print(x,"\t", f)
plt.plot(x,f, 'ro', markersize=1)
plt.show()
必须在列表中累积值才能绘制它们:
from math import exp, pi, sin
import matplotlib.pyplot as plt
xs = []
ys = []
for x in range(-4,5): # or range(-4, 6) if you need to plot a value for 5
f = (exp(-1*(x)**2))*sin(3*pi*(x))
print(x,"\t", f)
xs.append(x)
ys.append(f)
plt.plot(xs, ys, 'ro', markersize=1)
plt.show()
您只存储一个值。将值存储在列表中。范围不包括最后一个元素。