Matplotlib Python窃取屏幕焦点

问题描述 投票:4回答:1

我的代码从arduino获取串行数据,处理它,然后绘制它。我使用matplotlib作为图形界面。每次它“吸引”虽然它会引起人们的注意,但除此之外,用户将无法看到任何东西。让这个停下来的最好方法是什么? (代码工作正常,除了窃取焦点)。我尝试在另一篇文章中阅读后使用matplotlib.use('Agg')方法,但它没有用。 (使用MAC OS X)。

下面显示的代码是一个更新数据的超级简单图表,我遇到了同样的问题。我没有显示我的代码,因为没有正确的输入它是不可复制的。这是我的代码:

import matplotlib
from matplotlib import *
from pylab import *
# import math


x=[]
y=[]
def function(iteration):
    xValue=iteration#Assigns current x value
    yValue=(1./iteration)*34#Assigns current y value

    x.extend([xValue]) #adds the current x value to the x list
    y.extend([yValue]) #adds the current y value to the y list


    clf() #clears the plot

    plot(x,y,color='green') #tells the plot what to do 
    draw() #forces a draw

def main():

    for i in range(1,25): #run my function 25 times (24 I think actually)
        function(i)
        pause(.1)

main()
macos python-2.7 matplotlib focus graphing
1个回答
1
投票

您是否尝试过使用matplotlib的交互模式?

你可以使用ion()打开它(参见Documentation

如果您使用交互模式,则无需调用draw(),但可能需要使用clf()清除数字,具体取决于您所需的输出

© www.soinside.com 2019 - 2024. All rights reserved.