दो हिस्टोग्राम का बिन विड्थ समान रखने के लिए, हम डेटा के सेट का हिस्टोग्राम गणना कर सकते हैं।
चरण
-
<ली>रैंडम डेटा a, और नॉर्मल डिस्ट्रीब्यूशन b बनाएं।ली>
<ली>समान बिन विड्थ के लिए बिन्स वेरिएबल इनिशियलाइज़ करें।ली>
<ली>hist() मेथड का उपयोग करके a और बिन्स प्लॉट करें।ली>
<ली>hist() मेथड का उपयोग करके b और बिन्स प्लॉट करें।ली>
<ली>फिगर डिस्प्ले करने के लिए show() मेथड का उपयोग करें।ली>
उदाहरण
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
a = np.random.random(100) * 0.5
b = 1 - np.random.normal(size=100) * 0.1
bins = 10
bins = np.histogram(np.hstack((a, b)), bins=bins)[1]
plt.hist(a, bins, edgecolor='black')
plt.hist(b, bins, edgecolor='black')
plt.show()
आउटपुट
