当前,我尝试在绘图上显示我的随机数生成器的结果,但它是用不同的绘图显示出来的,而不是一次显示出来的。请查看我的代码:
import matplotlib.pyplot as plt
import random
global rand
rand = 1
def lcg():
a = 65539
c = 0
m = (2**31)
global rand
rand = (a*rand + c) % m
return rand
for i in range(10000):
plt.plot(rand, lcg(), 'o')
plt.show()
continue
我的编程不那么好,所以我不明白原因。如果您教我原因,将会非常有帮助。
答案 0 :(得分:0)
plot.show
在for循环之后具有一张包含所有必需点的图
import matplotlib.pyplot as plt
import random
global rand
rand = 1
def lcg():
a = 65539
c = 0
m = (2**31)
global rand
rand = (a * rand + c) % m
return rand
for i in range(100):
print (rand, lcg())
plt.plot(rand, lcg(), 'o')
continue
plt.show() # show outside for loop for one graph with all plots
因为每次调用plot.show()
都会显示一个图形,所以如果您运行代码,则必须关闭每个窗口10000次才能查看每个点。