ipython notebook and ginput

℡╲_俬逩灬. 提交于 2019-12-07 17:12:13

问题


I am trying to create an interactive plot in ipython notebook. I am attempting to run the sample code from matplotlib's website as below.

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

I get this error:

/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: 

I assume this has something to do with running ipython notebook and HTML. Is this possible to fix? and how?

thanks!!!


回答1:


If you started the ipython notebook using:

ipython notebook --pylab=inline

You don't need the show() function call. Plots will be automatically shown. The show() function is needed only when you use one of the qt, wx, gtk... backends.

Also, the ginput() function is not available in the inline mode. If you need it, you should start the notebook using some other backend that you have installed. For example qt or tk:

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


来源:https://stackoverflow.com/questions/18839341/ipython-notebook-and-ginput

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!