Scatter Plot Generation with Bokeh

  • Share this:

Code introduction


This function creates a scatter plot using the Bokeh library. It takes two lists as input, representing the x-axis and y-axis data.


Technology Stack : The package and technology stack used in the code[English]

Code Type : The type of code

Code Difficulty :


                
                    
def plot_scatter(x, y):
    from bokeh.plotting import figure, show
    from bokeh.models import ColumnDataSource

    # Create a ColumnDataSource with the data
    source = ColumnDataSource(data=dict(x=x, y=y))

    # Create a new plot with a title and axis labels
    p = figure(title="Scatter Plot", x_axis_label='X Axis', y_axis_label='Y Axis')

    # Add a scatter renderer to the plot
    p.scatter('x', 'y', source=source)

    # Display the plot
    show(p)