ipython notebook and ginput

2019-05-15 11:42发布

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条回答
劫难
2楼-- · 2019-05-15 12:22

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
查看更多
登录 后发表回答