成功解决plt.close()不work
原因:
Remember that plt.show() is a blocking function, so in the example code you used above, plt.close() isn't being executed until the window is closed, which makes it redundant.
You can use plt.ion() at the beginning of your code to make it non-blocking, although this has other implications.
解决方案:
在作图代码前加上plt.ion(),成功解决。
reference:
https://*.com/questions/20401057/matplotlib-close-does-not-close-the-window