I tried to create subplot by using some defined function, which returns directly plot. But I can't figure out why this is not working. for example:
my plot function is something like:
def plot_data(data):
plt.plot(data)
return plt.show()
suppose my data are:
data1 = np.random.rand(50)
data2 = np.random.rand(50)
data3 = np.random.rand(50)
data4 = np.random.rand(50)
and I am trying to create subplot with:
fig, ax = plt.subplots(nrows=2, ncols=2)
plt.subplot(2, 2, 1)
plot_data(data)
plt.subplot(2, 2, 2)
plot_data(data)
plt.subplot(2, 2, 3)
plot_data(data)
plt.subplot(2, 2, 4)
plot_data(data)
plt.tight_layout()
plt.show()

plt.subplot()andfig, ax = plt.subplots(nrows=2, ncols=2)plt.subplots(nrows=2, ncols=2)is unused.