如何在一个范围内绘制多条线?

时间:2019-06-02 16:54:22

标签: python plot bokeh

只是一个好奇的初学者编程问题。我想在1个图中绘制100个不同的列表。这是一款游戏,您可以选择每次掷硬币的起始资金和赌注。每次硬币落在头上时,您的赌注都会增加一倍,每次您放开筹码,您都会放掉此赌注。有比定义y1到y100更简单的方法吗?是仅在硬币翻转的第一行下方定义并绘制了脚本

我正在尝试使用bokeh绘图而不是matplot。

from bokeh.plotting import figure, show, output_file
import random
startcapital=int(input("What's the start capital?:"))
bet=int(input("What's the stakes?:"))
ioutcome=[]
outcome=[]
for i in range (100):
outcomei=[]
for i in range(10):
    i=random.randint(0,1)
    ioutcome.append(i)
    if startcapital>0:
        if i==1:
            startcapital+=bet
        if i==0:
            startcapital-=bet
    outcomei.append(startcapital)
outcome.append(outcomei)
x=[1,2,3,4,5,6,7,8,9,10]
y=outcome[1]
p = figure(plot_width=800, plot_height=400)
p.line(x, y, line_width=2)
show(p)

1 个答案:

答案 0 :(得分:0)

使用numpy,避免循环。阅读this

import numpy as np

shape = (10,)

start = np.ones(shape)

rnd = np.random.random_sample(shape)

start[rnd > 0.5] *= 2.0
start[rnd <= 0.5] = 0.0

print(start)