You can download this code by clicking the button below.
This code is now available for download.
This function uses the Bokeh library to generate a line plot based on random data. It first creates a ColumnDataSource to store the data, then creates a new figure object, and adds a line renderer to display the data.
Technology Stack : Bokeh, ColumnDataSource, figure, line, show
Code Type : Graphics drawing
Code Difficulty : Intermediate
import numpy as np
from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource
from bokeh.layouts import row
def random_plot(x_values, y_values):
# Create a ColumnDataSource
source = ColumnDataSource(data=dict(x=x_values, y=y_values))
# Create a new plot with a title and axis labels
p = figure(title="Random Data Plot", x_axis_label='X Values', y_axis_label='Y Values')
# Add a line renderer with legend and line thickness
p.line('x', 'y', source=source, legend_label="Line", line_width=2)
# Display the results
show(p)
# Example usage:
# x_values = np.random.random(100)
# y_values = np.random.random(100)
# random_plot(x_values, y_values)