Generating Random Data Points with Scatter Plot

  • Share this:

Code introduction


This function generates random data points using numpy and plots them on a scatter plot using matplotlib.


Technology Stack : numpy, matplotlib

Code Type : Graphics drawing

Code Difficulty : Intermediate


                
                    
import random
from datetime import datetime
import numpy as np
import matplotlib.pyplot as plt

def plot_random_data(x_range=100, y_range=100):
    # Generate random data points
    x = np.random.randint(1, x_range, size=100)
    y = np.random.randint(1, y_range, size=100)
    
    # Create a scatter plot
    plt.scatter(x, y)
    
    # Add a title and labels
    plt.title("Random Data Points")
    plt.xlabel("X-axis")
    plt.ylabel("Y-axis")
    
    # Show the plot
    plt.show()