You can download this code by clicking the button below.
This code is now available for download.
This function uses the Histogram class from the Bokeh library to create a histogram. If no data is provided by the user, it generates random data. Users can also specify the ranges for the x and y axes as well as the title of the histogram.
Technology Stack : Bokeh, Histogram, Numpy
Code Type : The type of code
Code Difficulty : Intermediate
def random_histogram(data, x_range=None, y_range=None, title="Random Histogram"):
from bokeh.plotting import figure, show
from bokeh.charts import Histogram
from numpy.random import randint
import numpy as np
# Generate random data if not provided
if data is None:
data = np.random.normal(0, 1, 1000)
# Create a histogram using Bokeh
h = Histogram(data, x_range=x_range, y_range=y_range, title=title)
h.render()
# Display the histogram
show(h)