You can download this code by clicking the button below.
This code is now available for download.
This code defines a function named `random_bar_chart` that takes two lists `x` and `y` as arguments and generates a bar chart based on random data.
Technology Stack : The code uses the Bokeh library for plotting, specifically the `figure`, `show`, and `ColumnDataSource` classes, as well as the `bars` method for rendering the bar chart.
Code Type : Function
Code Difficulty :
def random_bar_chart(x, y):
import random
from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource
# Generate random data
data = {
'x': x,
'y': [random.randint(1, 100) for _ in x]
}
source = ColumnDataSource(data)
# Create a new plot with a title and axis labels
p = figure(title="Random Bar Chart", x_axis_label='X Values', y_axis_label='Y Values')
# Add a bar renderer with the data
p.bars('x', 'y', source=source, fill_color='blue', line_color='black')
# Show the results
show(p)