2016-10-12 106 views
0

考虑一个循环按照下面的代码内的刷新图:调试使用在缩放选项期间waitforbuttonpress()matplotlib可能的错误

import matplotlib.pyplot as plt 

def fun_example(): 

    plt.ion() 
    for ite in range(3): 
     x = np.linspace(-2,6,100) 
     y = (ite+1)*x 

     figura = plt.figure(1) 
     plt.plot(x,y,'-b') 
     plt.waitforbuttonpress() 
     plt.close() 
    #endfor ite 

#enddef fun_example 

if __name__ == '__main__': 
    fun_example() 
#endif main 

的想法是检查用鼠标数字(例如,图中的工具栏),一旦完成,按下按钮继续执行代码。至少在我的情况下(Windows 7,python 3.4.4,spyder 3.0.0dev),如果我打算在图形中单击鼠标进行缩放,效果与按下按钮相同。换句话说waitforbuttonpress()返回确实,并且该图不见了。

有什么建议吗?它可能是一个错误?感谢你们所有人提前。

回答

2

the documentation.waitforbuttonpress()将返回True如果按一个键,False如果按下鼠标按键。因此,你想要的可能是这样的:

while True: 
    if plt.waitforbuttonpress(): 
     break 
+0

谢谢你的答案。我看到了文档,不幸的是,如果鼠标点击图形曲线,函数* waitforbuttonpress()*将返回* True *。 –

+0

我试图删除我自己的评论,但我不知道该怎么做。对不起,你是对的。谢谢您的帮助。我认为它抛出*真*只要等待结束,尽管返回*假* –