Random Data Histogram Plotting Function

  • Share this:

Code introduction


This code defines a function to generate random data and plot a histogram. It first generates a specified number of random data points using numpy, and then uses the hist function of matplotlib to plot the histogram.


Technology Stack : This code uses the numpy and matplotlib packages to generate random data and plot a histogram. The numpy package is used to generate random data, and the matplotlib package is used to plot the histogram.

Code Type : Function

Code Difficulty :


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

def plot_random_histogram(data_points, bins):
    """
    Plots a random histogram using numpy and matplotlib.

    Args:
        data_points (int): Number of data points for the histogram.
        bins (int): Number of bins for the histogram.
    """
    # Generate random data
    data = np.random.randn(data_points)
    
    # Plot the histogram
    plt.hist(data, bins=bins)
    plt.title('Random Histogram')
    plt.xlabel('Value')
    plt.ylabel('Frequency')
    plt.show()

# Example usage
plot_random_histogram(100, 10)