Scatter Plot Generation with Bokeh and Numpy

  • Share this:

Code introduction


This function creates a scatter plot using the Bokeh library, where the x-axis and y-axis represent the x and y coordinates of the input data points. The data points are generated using the Numpy library.


Technology Stack : Bokeh, Numpy

Code Type : Data visualization

Code Difficulty : Intermediate


                
                    
import numpy as np
from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource

def generate_scatter_plot(data_points):
    # Create a ColumnDataSource for the data
    source = ColumnDataSource(data_points)

    # 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)

# Sample data for the scatter plot
data_points = {
    'x': np.random.normal(0, 1, 100),
    'y': np.random.normal(0, 1, 100)
}

# Function call
generate_scatter_plot(data_points)                
              
Tags: