在 Python 解释器中执行这些指令后,您会看到一个带有绘图的窗口:
from matplotlib.pyplot import *
plot([1,2,3])
show()
# other code
很遗憾,在程序进行进一步计算的同时,我不知道如何继续交互式地探索 show()
创建的图形。
有可能吗?有时计算很长,如果在检查中间结果的过程中继续计算会有所帮助。
最佳答案
使用不会阻塞的matplotlib
的调用:
使用draw()
:
from matplotlib.pyplot import plot, draw, show
plot([1,2,3])
draw()
print('continue computation')
# at the end call show to ensure window won't close.
show()
使用交互模式:
from matplotlib.pyplot import plot, ion, show
ion() # enables interactive mode
plot([1,2,3]) # result shows immediatelly (implicit draw())
print('continue computation')
# at the end call show to ensure window won't close.
show()
关于python - 有没有办法分离 matplotlib 图以便计算可以继续?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/458209/