You can download this code by clicking the button below.
This code is now available for download.
This function generates a random color based on a given seed and creates a rectangle plot with that color using the Bokeh library.
Technology Stack : Bokeh
Code Type : Custom function
Code Difficulty : Intermediate
def random_color_hex(seed):
import random
from bokeh.plotting import figure, show
from bokeh.transform import transform
from bokeh.layouts import gridplot
# Generate a random color based on the seed
random.seed(seed)
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
random_color = f'#{r:02x}{g:02x}{b:02x}'
# Create a figure
p = figure(title="Random Color Hex", tools="save", width=200, height=100)
# Add a rectangle with the random color
p.rect(x=0, y=0, width=200, height=100, fill_color=random_color)
# Show the plot
show(p)
return random_color