我的代码从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()
答案 0 :(得分:1)
您是否尝试过使用matplotlib的交互模式?
您可以使用ion()打开它(参见Documentation)
如果您使用交互模式,则无需调用draw(),但可能需要使用clf()清除数字,具体取决于您所需的输出
答案 1 :(得分:0)