Random Data Line Chart Plotting Function

  • Share this:

Code introduction


This function uses the Matplotlib library to plot a line chart based on random data. It takes two lists as input, representing the x-axis and y-axis data points.


Technology Stack : Matplotlib library, NumPy library, plotting, line chart, random data generation

Code Type : The type of code

Code Difficulty : Advanced


                
                    
def plot_random_data(x, y):
    import matplotlib.pyplot as plt
    import numpy as np
    
    # Generate a random figure
    plt.figure(figsize=(10, 6))
    
    # Generate a random color
    color = np.random.rand(3,)
    
    # Plot the data
    plt.plot(x, y, color=color, marker='o')
    
    # Add title and labels
    plt.title('Random Data Plot')
    plt.xlabel('X-axis')
    plt.ylabel('Y-axis')
    
    # Show the plot
    plt.show()