'Bokeh Histogram of Roulette Game not showing up, am I missing something?

So I'm making a roulette game, here are the guidelines:

Roulette is a casino game that involves a steel ball spinner around a wheel. There are 38 slots where the ball might drop. 18 of those slots are colored red, another 18 are colored black and 2 are colored green. When you bet on either red or black and win, you get back twice the amount of your original bet. For example, if you bet $1, you would get an extra $1 for winning, but you would lose that original $1 if you lost.

Simulate 200 people playing roulette, each betting $1 on red 100 times. Create a line chart and an appropriate histogram that describes these results. Make sure to label your line chart and histogram.


So I believe my code for the game is right, but the histogram is showing up as a blank graph without anything on it. Am I missing something? Is there something else I need to add or incorporate?


Here's what I have written for this.

import math
import random
import numpy as np
from bokeh.plotting import figure, show

def roulette(x):
    results = []
    count = 0
    for i in range(1, x):
        roll = random.randint(1, 38)
        if roll <= 18:
            count += 1
            results.append(count/i)
        else:
            count -= 1
            results.append(count/i)
   
    return results

def listf(x):
    for i in range(x):
        return(roulette(100)[-1])

roulette_list = listf(200)

hist = np.histogram(roulette_list, bins = 10, range = (0, 200))

yval = hist[0]
xval = hist[1]

xbarwidth = xval[1] - xval[0]

xval = xval + xbarwidth/2
xval = xval[0:-1]

print(xval)

f = figure()
for x, y in zip(xval, yval):
    f.vbar(x, xbarwidth, y, line_color = "white")

show(f)


Solution 1:[1]

Your bokeh code works perfectly, here you can see a minimal example with self defined xval and yval.

xval = [1,2,3,4]
yval = [1,2,3,4]
xbarwidth = 1
f = figure()
for x, y in zip(xval, yval):
    f.vbar(x, xbarwidth, y, line_color = "white")
show(f)

simple bar plot

You have to ckeck your implementation for the roulette() and listf. If you call

roulette_list = listf(200)

this returns only one value right now and than np.histogram doesn't work as intended.

Edit My you can substitute your call roulette_list = listf(200) function with roulette_list =np.random.randint(0, 38, size=200, dtype=int). If you do so for a test, you will see some output in your figure.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1