Trying loop approach,
CodePudding user response:
You can use for loop and iterate over subplots. A very simple example is shown below.The subplots method creates the figure along with the subplots and store in the ax
array.
import matplotlib.pyplot as plt
x = np.linspace(0, 10)
y = range(10)
fig, ax = plt.subplots(nrows=2, ncols=2)
for row in ax:
for col in row:
col.plot(x, y)
plt.show()
for in range(2):
for j in range(2):
ax[i, j].plot(x,y)
CodePudding user response:
Then one idea is to take the signals into an array of shape=(20,1)
, where each row corresponds to signal amplitude or some other measurable quantity. Then you could do as below (check the output keeping only the lines till plt.text
you will get the idea).
for i in range(1, 21):
plt.subplot(5, 4, i)
plt.text(0.5, 0.5, str((5, 4, i)),
fontsize=18, ha='center')
period_freq,prog = LSP_scipy(signal[i])
plt.plot(period_freq, prog)
CodePudding user response:
- See inline comments to add and flatten the subplots.
- This is an implementation of flattening the
axes array
from this