【问题标题】:Prevent figures from closing when running a script from the command line从命令行运行脚本时防止图形关闭
【发布时间】:2013-11-14 00:04:47
【问题描述】:

当我从 shell 命令行运行我的代码时,它会打开图形窗口并显示绘图,但一旦代码完成它就会关闭它。我没有任何 close() 语句。

使用 ipython 从命令行运行 python 脚本时,如何防止图形关闭?

我可以在最后添加一条语句,仅在按下任意键后退出,但这感觉太像黑客了。

【问题讨论】:

  • 您是在 within ipython 中运行,如 In [n]: run script 还是在 shell 命令行 使用 ipython,如 $ ipython script.py?跨度>
  • 在外壳中。我会在问题中澄清。

标签: python python-2.7 matplotlib ipython


【解决方案1】:

我发现我需要使用 plt.show() 而不是 plt.draw()。

【讨论】:

    【解决方案2】:

    我喜欢用

    plt.draw()
    plt.pause(0.01)
    input("<Hit Enter To Close>")
    

    这样我就可以从命令行关闭绘图,而不必单击。

    【讨论】:

    • 我没想到会在这里找到你,Tumnus 先生。
    猜你喜欢
    • 2019-08-26
    • 1970-01-01
    • 2010-09-19
    • 2016-10-01
    • 2017-12-07
    • 2019-12-12
    • 2018-10-05
    • 2020-03-15
    • 2012-05-03
    相关资源
    最近更新 更多