【问题标题】:ipython notebook and ginputipython 笔记本和 ginput
【发布时间】:2013-09-17 08:41:38
【问题描述】:

我正在尝试在 ipython 笔记本中创建交互式绘图。我正在尝试从 matplotlib 的网站运行示例代码,如下所示。

t = arange(10)
plot(t, sin(t))
print("Please click")
x = ginput(3)
print("clicked",x)
show()

我收到此错误:

/Library/Python/2.7/site-packages/matplotlib/backend_bases.pyc in start_event_loop(self, timeout)
2370         This is implemented only for backends with GUIs.
2371         """
-> 2372         raise NotImplementedError
2373 
2374     def stop_event_loop(self):

NotImplementedError: 

我认为这与运行 ipython 笔记本和 HTML 有关。这可以解决吗?以及如何?

谢谢!!!

【问题讨论】:

    标签: python matplotlib ipython ipython-notebook


    【解决方案1】:

    如果您使用以下方式启动 ipython 笔记本:

    ipython notebook --pylab=inline
    

    您不需要show() 函数调用。绘图将自动显示。仅当您使用 qtwxgtk... 后端之一时,才需要 show() 函数。

    另外,ginput() 功能在inline 模式下不可用。如果您需要它,您应该使用已安装的其他一些后端来启动 notebook。例如qttk

    ipython notebook --pylab=qt
    ipython notebook --pylab=tk
    

    【讨论】:

    • 是的,错误是在 x = ginput(3) 的那一行之前生成的
    • @jmerkow 哦,对不起,我错过了。当您使用inline 模式时,ginput 也不可用。
    • @jmerkow 如果您需要这些功能,您应该使用其他一些后端启动笔记本。更新了答案。
    猜你喜欢
    • 2018-09-03
    • 1970-01-01
    • 1970-01-01
    • 2017-05-15
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多