python - ipython 笔记本和 ginput

标签 python matplotlib ipython jupyter-notebook

我正在尝试在 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 notebook 和 HTML 有关。这可能修复吗?以及如何?

谢谢!!!

最佳答案

如果您使用以下方式启动 ipython notebook:

ipython notebook --pylab=inline

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

此外,ginput() 函数在inline 模式下不可用。如果需要,您应该使用已安装的其他后端启动笔记本。例如qttk:

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

关于python - ipython 笔记本和 ginput,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18839341/

相关文章:

python - ssl.SSLError : [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl. c :852) in Docker Python:3. 6-slim

python - 如何优化/简化堆排序 Django 对象? (不能使用模块和数据库排序)

python - 集合协调算法的实现

Python - 如何使 DataFrame 图不总是打印在单元格输出的底部?

sql-server - 为 python3.6 安装了 pymssql,但在 Spyder 的 IPython 控制台中找不到模块

ipython - IPython并行引擎的实时输出?

python - 理解 IPython 中的 numpy.linalg.norm()

python - 在不使用 osascript 或 appscript 的情况下从 Python 调用 AppleScript?

data.plot(x=data.timestamp, 样式 =".-") 上的 Python 错误

python - pandas:用标签绘制时间序列的多列(来自 pandas 文档的示例)