import numpy as np
import matplotlib.pyplot as plt
# Create a sample dataset
data = np.random.randn(1000)
# Calculate the number of bins
num_bins = 10
# Create a histogram
hist, bins = np.histogram(data, bins=num_bins)
# Plot the histogram
plt.bar(bins[:-1], hist, width=bins[1] - bins[0])
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.title("Histogram of Sample Data")
plt.show()
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter