I need to plot many plots, take a look at them and press either "y" or "n". I can't get matplotlib showing plots one-by-one in a loop. The loop must show me a plot, then I will press some button and it starts again. My code for now is:
def press_event(event):
answer = event.key
if answer=='y':
pass
sys.stdout.flush()
print(answer)
files = os.listdir(folder)
fig, ax = plt.subplots(14,2, figsize=(10,30))
fig.canvas.mpl_connect('key_press_event', press_event)
for file in files:
target = file
data = pd.read_csv(folder + target)
fig.suptitle(target, fontsize=30)
r = 0
for key in data:
sample = data[key]
ts = [sample[i+1] - sample[i] for i in range(len(sample)-1)]
decs,ts,point = cusum(sample,10)
ax[r,0].plot(sample)
ax[r,0].axvline(point,color='red')
ax[r,1].plot(decs)
ax[r,1].axvline(point, color='red')
r += 1
plt.show()
fig.canvas.draw()
plt.waitforbuttonpress()
plt.pause(0.1)
fig.clear()
Now it shows me the first plot. I press a button and next window is blank and kernel crashes.