I am trying to loop subplot for n rows 2 columns for Gaussian function as shown in following example code. This returns histogram and normal distribution, I tried a couple of methods unsuccessfully, any help is most appreciated.
Speed = [0,10,20,30,40]
Torque1 = []
Torque2 = []
for i in range(5):
Trq = np.random.normal(0, 10, 5)
Torque1.append(Trq)
for i in range(5):
Trq = np.random.normal(0, 10, 5)
Torque2.append(Trq)
def gaussian_Histo(s, Title):
mu, sigma = np.mean(s), np.std(s, ddof=1) # mean and standard deviation
fig = plt.figure(Title, figsize=(10, 6), dpi=80)
count, bins, ignored = plt.hist(s, 80, normed=True)
plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) *np.exp( - (bins - mu)**2 / (2 * sigma**2) ), linewidth=2, color='r')
plt.grid(True)
plt.title(Title)
plt.show()
def main():
nrows = 3
fig, axes = plt.subplots(nrows, 2)
for row in axes:
# for i in range(3):
x = gaussian_Histo(Torque1[i], 'Torque at'+str(Speed[i])+'RPM')
y = gaussian_Histo(Torque2[i], 'Torque at'+str(Speed[i])+'RPM')
plot(row, x, y)
plt.show()
def plot(axrow, x, y):
axrow[0].plot(x, color='red')
axrow[1].plot(y, color='green')
main()