基本上你面临两个问题
“%pylab inline”调用重写matplotlib.use文件('nbagg')
调用,使用“inline”后端,而不是实际需要的“nbagg”后端。如果使用最新版本的IPython(2.3),则可以直接使用“%matplotlib nbagg”(或“%matplotlib notebook”)加载nbagg后端,而不是使用“%pylab”调用。
一旦启用了u nbaggu后端,就需要显式显示它,即添加一个
节目()call at the end of your script->Update:对于IPython 2.3.1,这不再需要了(感谢@tcaswell的提示)
这样,您就可以在
IPython笔记本。但是,快速尝试代码并不会让
期望的结果。按钮会做出反应并执行回调,但“print`
电话里什么也看不出来。不管怎样,要看到它的工作尝试以下
简单示例(需要IPython 2.3):
%matplotlib nbaggfrom matplotlib.widgets import Buttonimport matplotlib.pyplot as pltdef callback(event): plt.text(event.xdata, event.ydata, 'clicked')f,a = plt.subplots(1)b1 = Button(a,'Button1')b1.on_clicked(callback)plt.show()
另外,强烈建议以后使用%matplotlib而不是%pylab
导致一些副作用,参见
这里.



