Creating a Scatter Plot with Bokeh

  • Share this:

Code introduction


This function creates a scatter plot using the Bokeh library, which takes x and y coordinate values and a title as parameters and displays them.


Technology Stack : Bokeh library

Code Type : Data visualization

Code Difficulty : Intermediate


                
                    
def plot_scatter(x_values, y_values, title="Scatter Plot"):
    from bokeh.plotting import figure, show
    from bokeh.models import Circle, HoverTool

    p = figure(title=title, tools="pan,wheel_zoom,box_zoom,reset", width=600, height=400)
    p.circle(x_values, y_values, size=10, color='blue', alpha=0.5)

    hover = HoverTool(
        tooltips=[
            ("x", "$x"),
            ("y", "$y"),
        ]
    )
    p.add_tools(hover)

    show(p)                
              
Tags: