实时绘图不显示

2024-09-26 17:44:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用plt.plot()pyplot绘制FTDI端口的传感器数据。不幸的是,不知什么原因,我没有看到一条线。但是,当我更改mark type:plt.plot(duration, temp, 'o')(或其他任何类似marktype的点)时,一切都会正常进行。我试图增加睡眠时间(阅读plot问题和其他类似问题的实时绘图),但事实并非如此

#!/usr/bin/python


import time
import numpy as np
import matplotlib.pyplot as plt

print "We are plotting sonar values"
f = open('/dev/ttyUSB0', 'r')

plt.axis()
plt.ion()
plt.show()
duration = 0;
while True:
    print f.readline()
    temp = f.readline()

    temp = int(temp[1:])
    plt.plot(duration, temp, 'o')
    duration+=1
    plt.draw()
    time.sleep(0.1)

enter image description hereenter image description here


Tags: 数据端口importreadlinetimeplotas绘制

热门问题