python - 在 Enthought Canopy IDE 中执行脚本时 matplotlib.figure() 不起作用

标签 python matplotlib enthought canopy

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

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 接口(interface) ( matplotlib.pyplot.figure ) 创建的图形将被保留,直到显式关闭为止,并且可能会消耗太多内存。 (要控制此警告,请参阅 rcParam figure.max_num_figures )。 max_open_warning,运行时警告)

Edit2:这似乎工作正常。

import pylab

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

if __name__ == "__main__":
    ex1()

最佳答案

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

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

关于python - 在 Enthought Canopy IDE 中执行脚本时 matplotlib.figure() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27067368/

相关文章:

python - Django,重复一个相关查询时多次命中数据库

python - 带有标签列的堆叠列

python - Matplotlib 轴标签

datetime - 使用 matplotlib 作为日期刻度的语言为英语

python - Matplotlib-动画 "No MovieWriters Available"

python - 设置属性时如何避免循环依赖?

python - Enthought Canopy Windows 注册表项丢失

python - 如何卡住可变的默认参数值?

python - 关于 Enthought Traits/TraitsUI for Python 桌面开发的看法

Python 查找模式并替换整行