[英][matplotlib]: use of ginput on Jupyter %matplotlib notebook
我想在Jupyter上使用matplotlib方法“ginput”,使用“%matplotlib notebook”,但它不起作用。 在这里,您可以看到ginput示例 。 如果我复制并通过Spyder上的代码然后它可以工作,但是如果我将它粘贴在Jupyter上然后我得到以下错误消息
Please click
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-24-50d3ac899b10> in <module>()
7 plt.plot(t, np.sin(t))
8 print("Please click")
----> 9 x = plt.ginput(3)
10 print("clicked", x)
11 plt.show()
C:\Users\fedel\Anaconda2c\lib\site-packages\matplotlib\pyplot.pyc in ginput(*args, **kwargs)
709 If *timeout* is negative, does not timeout.
710 """
--> 711 return gcf().ginput(*args, **kwargs)
712
713
C:\Users\fedel\Anaconda2c\lib\site-packages\matplotlib\figure.pyc in ginput(self, n, timeout, show_clicks, mouse_add, mouse_pop, mouse_stop)
1663 mouse_stop=mouse_stop)
1664 return blocking_mouse_input(n=n, timeout=timeout,
-> 1665 show_clicks=show_clicks)
1666
1667 def waitforbuttonpress(self, timeout=-1):
C:\Users\fedel\Anaconda2c\lib\site-packages\matplotlib\blocking_input.pyc in __call__(self, n, timeout, show_clicks)
292 self.clicks = []
293 self.marks = []
--> 294 BlockingInput.__call__(self, n=n, timeout=timeout)
295
296 return self.clicks
C:\Users\fedel\Anaconda2c\lib\site-packages\matplotlib\blocking_input.pyc in __call__(self, n, timeout)
115 try:
116 # Start event loop
--> 117 self.fig.canvas.start_event_loop(timeout=timeout)
118 finally: # Run even on exception like ctrl-c
119 # Disconnect the callbacks
C:\Users\fedel\Anaconda2c\lib\site-packages\matplotlib\backends\backend_nbagg.pyc in start_event_loop(self, timeout)
192
193 def start_event_loop(self, timeout):
--> 194 FigureCanvasBase.start_event_loop_default(self, timeout)
195
196 def stop_event_loop(self):
C:\Users\fedel\Anaconda2c\lib\site-packages\matplotlib\backend_bases.pyc in start_event_loop_default(self, timeout)
2443 self._looping = True
2444 while self._looping and counter * timestep < timeout:
-> 2445 self.flush_events()
2446 time.sleep(timestep)
2447 counter += 1
C:\Users\fedel\Anaconda2c\lib\site-packages\matplotlib\backend_bases.pyc in flush_events(self)
2388 backends with GUIs.
2389 """
-> 2390 raise NotImplementedError
2391
2392 def start_event_loop(self, timeout):
NotImplementedError:
你有什么建议我在Jupyter上制作“ginput”方法?
因为我只是玩同样的例子,起初无法让它工作(虽然有不同的问题,从来没有得到那个具体的错误信息),这里终于为我工作了:
添加
import matplotlib
matplotlib.use('TkAgg')
之前
import matplotlib.pyplot as plt
然后在单独的窗口中打开绘图,该窗口在交互结束时关闭。
由于我希望在较长的脚本中进行最终的绘图交互,我希望所有其他绘图以内联方式显示,但是必须在单独的窗口中打开交互式绘图,我的脚本现在具有以下格式:
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
%matplotlib inline
# some plots
%matplotlib qt
# the interactive plot
%matplotlib inline
# the other plots
我尝试了很多我在网上找到的不同的东西,但只有在这种组合中我才能做到我想要的东西;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.