python程序结束前绘图的生成

2024-09-30 03:21:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着绘制两个数组的元素。虽然绘图工作正常,但在询问用户是否要继续之前,它不会生成图像。 (此代码嵌入while true循环中)。在

    print 'To achieve the million pound goal using your betting strategy, you would have to spin the wheel approximately',averageiterations, 'times on average.'
    print 'The theoretical probability of you obtaining a million based on your betting strategy is: %9.7e' % p
    print 'The approximate average total amount of times that you ran out of money while using your betting strategy (went below the minimum bet) is:',len(fails)/1000.,', which rounds up to', int(math.ceil(len(fails)/1000.)),'.'

i=0
millions=[]
millionspins=[]
while i<1000:
    millions.append(allnewbank[:][i][-1])
    i=i+1
i=0
while i<1000:
    millionspins.append(len(allnewbank[:][i]))
    i=i+1
fig = plt.figure()
matplotlib.pyplot.scatter(millionspins,millions)
plt.xlabel("Number of spins")
plt.ylabel("Bank")
plt.xlim(0,max(millionspins))
plt.ylim(1000000,max(millions))
plt.show()
while restart not in exit:
        restart=raw_input('Please type "y" to restart or "n" to exit:')
    if restart==exit[0]:
            continue    
    if restart==exit[1]:
        break

Tags: ofthetoyouyourlenexitplt
1条回答
网友
1楼 · 发布于 2024-09-30 03:21:59

最好能看到程序在哪里请求用户输入。不过,我想你要问的是,如何显示一个情节并继续程序?如果是这样,您只需禁用matplotlib来阻止程序:

plt.show(block = False)

相关问题 更多 >

    热门问题