Python-有没有办法分离matplotlib图,以便继续计算?

发布于 2021-02-02 23:13:23

在Python解释器中执行以下指令后,将获得一个带有绘图的窗口:

from matplotlib.pyplot import *
plot([1,2,3])
show()
# other code

不幸的是,show()当程序进行进一步的计算时,我不知道如何继续以交互方式探索创建的图形。

有可能吗?有时计算很长,如果可以在检查中间结果时进行计算,则将有所帮助。

关注者
0
被浏览
82
1 个回答
  • 面试哥
    面试哥 2021-02-02
    为面试而生,有面试问题,就找面试哥。

    使用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()
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看