Python 相当于 Matlab 的 clear、close all、clc
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32215532/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python equivalent of Matlab's clear, close all, clc
提问by AlanH
In Matlab, at the beginning of every file, I usually write
在Matlab中,在每个文件的开头,我通常写
clear; close all; clc
Is there something similar to this in Python? What do most people do when testing their scripts?
Python中有没有类似的东西?大多数人在测试脚本时会做什么?
回答by Ben
The catch here is that plt.show() is blocking and will not return to the script until the window is closed manually. You can try plt.draw(), which is interactive and will allow the script to continue running after the figure has been drawn.
这里的问题是 plt.show() 正在阻塞并且在手动关闭窗口之前不会返回到脚本。您可以尝试 plt.draw(),它是交互式的,将允许脚本在图形绘制后继续运行。
There is another question which discusses the difference between show and draw:
还有一个问题讨论了显示和抽奖之间的区别:
Difference between plt.show() and plt.draw()
Then the close should work.
然后关闭应该工作。
回答by kashanipour
I using either
我使用
print ("\n"*80)
Or
或者
import os
clear = lambda: os.system('cls') # On Windows System
clear()
回答by AlbiBone
To close the figure, use:
要关闭图形,请使用:
plt.close('all');