[英]How to make live graphs plotted in a single one graph?
I'm trying to show real-time graphs(dynamic plotting) using python. 我正在尝试使用python显示实时图形(动态绘图)。 However, the result didn't show in a single one graph, but generate a new one each second, which didn't mean updating live graph. 但是,结果并没有显示在单个图形中,而是每秒生成一个新图形,这并不意味着更新实时图形。 How can I solve it? 我该如何解决? Is there any problem in my code? 我的代码有什么问题吗?
import serial
import time
import matplotlib.pyplot as plt
from drawnow import drawnow
DataList = []
pcs = serial.Serial('COM4', baudrate = 9600, timeout = 1)
time.sleep(3)
plt.ion()
def makeFig():
plt.plot(DataList, 'rd-')
def getValues():
pcs.write(b"MEASure:VOLTage:DC?\n")
pcsData = pcs.readline().decode('ascii').split('\n\r')
DataList.append(float(pcsData[0]))
while(1):
getValues()
drawnow(makeFig)
plt.pause(.000001)
the drawnow
called in this way is designed as one-shot draw. 以这种方式调用的drawnow
被设计为一次抽签。 See if drawnow(caller, show_once=True)
corrects your problem, else you may need to look elsewhere - such as using alternative plotting functions: 查看drawnow(caller, show_once=True)
解决了您的问题,否则您可能需要在其他地方查找-例如使用其他绘图功能:
How do I plot in real-time in a while loop using matplotlib? 如何使用matplotlib在while循环中实时绘制?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.