【问题标题】:matplotlib.figure() doesn't work when executing a script in Enthought Canopy IDE在 Enthought Canopy IDE 中执行脚本时 matplotlib.figure() 不起作用
【发布时间】:2015-01-19 22:53:05
【问题描述】:

当我在 Enthought Canopy 编辑器的 Python shell 中执行 pyplot.figure() 时,会显示一个图形菜单。但是当我运行以下脚本时,没有显示图形菜单?

from matplotlib import pyplot

def ex1():
    pyplot.figure()

if __name__ == "__main__":
    ex1()

编辑:我在重新执行脚本“几次”后收到以下消息。但我没有看到一个数字。 C:\Users\Matthias\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\pyplot.py:412: RuntimeWarning: 已打开超过 20 个图形。通过 pyplot 接口 (matplotlib.pyplot.figure) 创建的图形会一直保留到显式关闭,并且可能会消耗太多内存。 (要控制此警告,请参阅 rcParam figure.max_num_figures)。 max_open_warning, RuntimeWarning)

Edit2:这似乎工作正常。

import pylab

def ex1():
    pylab.figure()
    pylab.show()

if __name__ == "__main__":
    ex1()

【问题讨论】:

    标签: python matplotlib enthought canopy


    【解决方案1】:

    show() 是使用 matplotlib 绘图时正常编程序列的最后一步:组装所有组件,然后显示结果。

    在以 pylab 或 matplotlib 模式运行的 IPython 中(Canopy,默认情况下以 pylab 模式运行 IPython),直接在 IPython 提示符下完成的绘图命令会在您输入时一一显示。这是一个特殊的 IPython 功能,可让您与绘图进行交互。 (IPython 中的“I”代表交互式。)

    【讨论】:

      猜你喜欢
      • 2014-11-13
      • 1970-01-01
      • 2013-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多