简体   繁体   English

plt.close('all')没有关闭图像,因此下一个语句没有被删除

[英]plt.close('all') is not closing the image and hence the next statement is not getting excecuted

Plt.close('all') is not closing the image and hence the next statement is not getting excecuted Plt.close('all')没有关闭图像,因此下一个语句没有被删除

Tried to do plt.close('all') 试图做plt.close('all')

import tensorflow as tf
import matplotlib.pyplot as plt 

mnist = tf.keras.datasets.mnist

(x_train, y_train), (x_test, y_test) = mnist.load_data()

print(x_train.shape)

plt.imshow(x_test[0])
plt.show()
plt.close('all')
print(tf.__version__)

Does not print tf.version until I close the image manually 在手动关闭图像之前不打印tf.version

This will show the figure for 3 seconds and close it automatically. 这将显示该图3秒并自动关闭它。

plt.show(block=False)
plt.pause(3)
plt.close()

or another option is to put plt.show() at the end of the file. 或另一种选择是将plt.show()放在文件的末尾。 The plt.close('all') will not be executed until you close the figure. 在关闭图形之前,不会执行plt.close('all')。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM