Creating a Random Scatter Plot with Bokeh and NumPy

  • Share this:

Code introduction


This function creates a scatter plot with random data using the Bokeh library and NumPy.


Technology Stack : Bokeh, NumPy

Code Type : Data visualization

Code Difficulty : Intermediate


                
                    
import numpy as np
from bokeh.plotting import figure, show
from bokeh.layouts import row

def generate_random_plot(width=400, height=400, num_points=50):
    # Generate random x and y data
    x = np.random.uniform(low=-10, high=10, size=num_points)
    y = np.random.uniform(low=-10, high=10, size=num_points)
    
    # Create a new plot with a title and axis labels
    p = figure(title="Random Data", width=width, height=height, x_axis_label='X', y_axis_label='Y')
    
    # Add a circle renderer with the random data
    p.circle(x, y, size=10, color='blue', alpha=0.5)
    
    # Display the plot
    show(p)                
              
Tags: