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(),成功解决。
https://stackoverflow.com/questions/20401057/matplotlib-close-does-not-close-the-window
原文:https://www.cnblogs.com/blog-joy/p/14303605.html