I'm trying to show real-time graphs(dynamic plotting) using 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)