我的代码正在从 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()