python - 在 Mac OS X 10.8.5 (Mountain Lion) 上使用 Enthought Canopy python 编辑器运行 matplotlib.pyplot 时没有显示绘图窗口

标签 python matplotlib plot enthought canopy

我已经在我的 Mac OS X v10.8.5 (Mountain Lion) 上安装了 Enthought Canopy 64 位,并且在 Canopy 命令行中我可以输入 import matplotlibmatplotlib。 pyplot.plot([1,2,3,4]) 绘图窗口打开就好了。

但是当我在 Canopy 编辑器窗口中运行完全相同的两行时,我什么也没得到,没有绘图窗口,也没有错误。

注意:当我运行 matplotlib.get_backend() 时,我得到了 Qt4Agg 的输出,无论我在命令行还是在编辑器窗口。

另一个注意:出于某种神秘的原因,当我单击 Canopy → 首选项时,我看到“Canopy 不是您的默认 Python 环境”,这很奇怪,因为当我运行 import sys 然后 sys.prefix 我得到 /Users/damon/Library/Enthought/Canopy_64bit/User,这应该保证 Canopy 是我的默认 Python 环境。

我该如何解决这个问题?

最佳答案

  1. IPython 的部分神奇之处在于,当您在 IPython 的 pylab 模式下绘图时,您无需显式调用 pyplot.show()。从您的脚本中,您确实需要这样做。

    https://support.enthought.com/entries/25750190-Modules-are-already-available-in-the-pylab-python-prompt-but-not-in-a-script (文章底部)

  2. 在 Canopy 本身中,Canopy User Python 实际上始终是您的 Python 环境。此首选项适用于终端中发生的情况(正如它在按钮上方用较小的字母解释的那样)。

关于python - 在 Mac OS X 10.8.5 (Mountain Lion) 上使用 Enthought Canopy python 编辑器运行 matplotlib.pyplot 时没有显示绘图窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21129055/

相关文章:

python - pyqtgraph:对齐不同图中x轴的刻度

python - pyplot 显示不良,图像太暗

python - Matplotlib 动画太慢(~3 fps)

r - 如何在图形的轴上插入点

python - BeautifulSoup: AttributeError: 'str' 对象没有属性 'copy' 。在 Ubuntu 上工作,在 Windows 上失败

python - 使用 python 2 根据自定义行顺序对 2D 锯齿状列表进行排序

Python3.8 : What's the difference between ImportError and ModuleNotFoundError

python - 100 步 100 名随机游走者的平均值

python - 如何在条形图(Python)的条形图上方写文字?

python - Python 中的交互式绘图?