【发布时间】:2017-07-29 20:40:03
【问题描述】:
我正在尝试遵循一些生成实时图的指南,例如:real-time plotting in while loop with matplotlib 和 http://thread.gmane.org/gmane.comp.python.matplotlib.general/35705
但是,我相信示例代码是使用 python 2.7 编译的。当我尝试编译我的时,我没有看到正在更新的实时绘图。这是因为python 3不支持吗?还是我错过了图书馆或其他什么?只有当我停止 while 循环时,我才会看到绘制的最后一个值。我使用 Rodeo 作为我的 IDE;这会阻止我查看实时情节吗?
import serial
import numpy as np
import matplotlib.pyplot as plt
def plotlive():
plt.plot(ard_dat,'o')
plt.xlabel('count', fontsize=12)
plt.ylabel('reading', fontsize=12)
plt.legend(loc='upper right')
ard_dat=[]
plt.ion()
cnt=0
arduinoSerialData = serial.Serial('com5',9600)
while True:
while (arduinoSerialData.inWaiting()==0):
pass
srdata = arduinoSerialData.readline()
try:
intstrdata = int(srdata)
except ValueError:
pass
ard_dat.append(intstrdata)
drawnow(plotlive)
plt.pause(.00001)
cnt+=1
if (cnt>50):
ard_dat.pop(0)
【问题讨论】:
标签: python matplotlib real-time