I would like to use matplotlib.pyplot to display many images in my jupyter notebook. However, when I try to display more than 20, a runtime warning appears, since images are kept in memory if not closed:
RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (
matplotlib.pyplot.figure
) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam figure.max_open_warning).
I am using %matplotlib inline
If I close the plot plt.close()
, the plots are not displayed. How can I can close the plot and still look at the plot in jupyter, I need to look at many images simultanously: I am using a loop where crop and value are two images.
plt.figure()
f, axarr = plt.subplots(1,2)
plt.title('Image: ' + str(key))
plt.gray()
axarr[0].imshow(crop)
axarr[1].imshow(value)
plt.close()
I think you would want to use plt.show()
at the end of your loop.
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
for i in range(25):
fig, ax_arr = plt.subplots(1,2)
ax_arr[0].imshow(np.random.randn(10,10))
ax_arr[1].imshow(np.random.randn(10,10))
plt.show()
There is then no need to close anything.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.