I am using python 3.6.7, matplotlib 2.2.2, ipython 7.0.1, notebook 5.6.0 and jupyter 1.0.0.
I would like create 10 plots displayed on 2 lines that will stay in the same place on the jupyter notebook during the loop and new results will be display every 10 iteration in the same 10 plots. Here some dummy code for illustration only.
import matplotlib.pyplot as plt
fig, ax = plt.subplots(2, 5, sharex='col', sharey='row', figsize=(40,15))
ax = ax.flatten()
for i in range(TRAIN_STEPS):
if i%10 == 0:
for j in range(10):
ax[j].set_title(j+i,fontsize=40)
ax[j].axes.get_xaxis().set_visible(False)
ax[j].axes.get_yaxis().set_visible(False)
ax[j].imshow(weight[i]), cmap=plt.get_cmap('seismic'))
if i%100 == 0:
print('Step:' + str(i))
I created the title with i+j to better see what was updated. In this example, the set of plots are only showed at the end (not during the loop).
If I use plt.show()
, then I only see the first set of plots
I don't want to save the plots at each set and do an animation later. Any idea if we can do that and how ? (I look at many things but I am missing something plt.ion()
plt.show(block=False)
plt.pause(1)
time.sleep(0.1)
f = plt.figure()
f.canvas.update()
f.canvas.flush_events()
f.canvas.draw_idle()