I have a long-running function and I would like to update an image as data arrive. Can anyone give me a hint on how to do that?
Consider the code of a cell: fig, axes = plt.subplots(1, 2) axes[0].imshow(np.eye(10)) axes[1].imshow(np.zeros((10, 10))) plt.show() import time print('Sleeping...') time.sleep(3) print('Awake!') axes[0].imshow(np.zeros((10, 10))) axes[1].imshow(np.eye(10)) plt.draw() plt.show() I would like to update the figure after the Awake
solved: fig, axes = plt.subplots(1, 2) axes[0].imshow(np.random.rand(3, 5)) axes[1].imshow(np.random.rand(3, 5)) fig.show() for i in range(10): axes[0].imshow(np.random.rand(3, 5)) axes[1].imshow(np.random.rand(3, 5)) display.clear_output(wait=True) display.display(fig) time.sleep(1.0)
Обсуждают сегодня