Creating and Displaying Scatter and Line Plots with Bokeh

  • Share this:

Code introduction


This function creates a scatter plot and a line plot, and displays them in a grid layout. It first imports the necessary libraries, then defines a function that takes two arrays as input and creates and displays charts using the Bokeh library.


Technology Stack : Bokeh, NumPy, Pandas

Code Type : The type of code

Code Difficulty : Intermediate


                
                    
import numpy as np
import pandas as pd
from bokeh.plotting import figure, show
from bokeh.layouts import gridplot

def create_scatter_plot(x, 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, color='blue', size=10)
    
    # Create a new plot with a different title and axis labels
    q = figure(title="Line Plot", x_axis_label='X Axis', y_axis_label='Y Axis')
    q.line(x, y, color='red', line_width=2)
    
    # Create a grid layout with two plots
    layout = gridplot([[p], [q]])
    
    # Display the plot
    show(layout)