print "Enter the amount of points you would like to generate to estimate Pi"
n = raw_input()
plt.xlim((0,1))
plt.ylim((0,1))
x = numpy.linspace(0,1,500)
y = numpy.sqrt(1-x**2)
for i in range(int(n)):
xcoordinate = random.random()
ycoordinate = random.random()
plt.scatter(xcoordinate, ycoordinate)
plt.plot(x,y,'g')
plt.show()
我试图在此图表中分散n
个随机点。相反,我只得到一个随机点。
我该如何解决这个问题?
答案 0 :(得分:0)
您可以将xcoordinate
和xcoordinate
转换为列表,然后在其中添加随机点。
xcoordinate=[]
ycoordinate=[]
for i in range(int(n)):
xcoordinate.append(random.random())
ycoordinate.append(random.random())
其余代码保持不变。