Jun-11-2017, 02:54 PM
Hello,
I'm trying to plot data which i receive from a serial com. It plots the data in a figure in 3 graphs.
I'm using the drawnow, but i can't find a way to change the x axis.
Right now the x axis just counts from zero to 10 and then it won't change at all.
I want to change the x axis into a timer.
For example: timer = 1000
Every time i receive data: timer = timer + 30
I want the timer as my x axis.
Can someone explain how i can do this?
I've put the code down below i think.
I'm trying to plot data which i receive from a serial com. It plots the data in a figure in 3 graphs.
I'm using the drawnow, but i can't find a way to change the x axis.
Right now the x axis just counts from zero to 10 and then it won't change at all.
I want to change the x axis into a timer.
For example: timer = 1000
Every time i receive data: timer = timer + 30
I want the timer as my x axis.
Can someone explain how i can do this?
I've put the code down below i think.
import serial import numpy import matplotlib.pyplot as plt from drawnow import * temperatuur1=[] temperatuur2=[] temperatuur3=[] luchtvochtigheid1=[] luchtvochtigheid2=[] luchtvochtigheid3=[] arduinoData = serial.Serial('com9') plt.ion() cnt1=0 cnt2=0 cnt3=0 def makeFig(): plt.figure(1) plt.subplot(311) plt.xlabel(' ') plt.ylim(15,30) plt.title('Weerstation') plt.grid(True) plt.ylabel(' ') plt.plot(temperatuur1, 'ro-',label='Temperatuur (C) Loc.1') plt.legend(loc='upper left') plt2=plt.twinx() plt.ylim(0,100) plt2.plot(luchtvochtigheid1, 'bo-', label='Luchtvochtigheid (%) Loc.1') plt2.set_ylabel(' )') plt2.ticklabel_format(useOffset=False) plt2.legend(loc='upper right') plt.subplot(312) plt.xlabel(' ') plt.ylim(15,30) plt.title(' ') plt.grid(True) plt.ylabel('Temperatuur (C)') plt.plot(temperatuur2, 'ro-',label='Temperatuur (C) Loc.2') plt.legend(loc='upper left') plt2=plt.twinx() plt.ylim(0,100) plt2.plot(luchtvochtigheid2, 'bo-', label='Luchtvochtigheid % Loc.2') plt2.set_ylabel('Luchtvochtigheid %') plt2.ticklabel_format(useOffset=False) plt2.legend(loc='upper right') plt.subplot(313) plt.xlabel('Laatste 10 metingen') plt.ylim(15,30) plt.title(' ') plt.grid(True) plt.ylabel(' ') plt.plot(temperatuur3, 'ro-',label='Temperatuur (C) Loc.3') plt.legend(loc='upper left') plt2=plt.twinx() plt.ylim(0,100) plt2.plot(luchtvochtigheid3, 'bo-', label='Luchtvochtigheid % Loc.3') plt2.set_ylabel(' ') plt2.ticklabel_format(useOffset=False) plt2.legend(loc='upper right') while True: while (arduinoData.inWaiting()==0): pass arduinoString = arduinoData.readline() dataArray = arduinoString.split(',') if float (dataArray[0]) == 1: temp1 = (dataArray[1]) lucht1 = (dataArray[2]) temperatuur1.append(temp1) luchtvochtigheid1.append(lucht1) cnt1 = cnt1+1 elif float (dataArray[0]) == 2: temp2 = (dataArray[1]) lucht2 = (dataArray[2]) temperatuur2.append(temp2) luchtvochtigheid2.append(lucht2) cnt2 = cnt2+1 elif float (dataArray[0]) == 3: temp3 = (dataArray[1]) lucht3 = (dataArray[2]) temperatuur3.append(temp3) luchtvochtigheid3.append(lucht3) cnt3 = cnt3+1 drawnow(makeFig) plt.pause(.000001) if(cnt1>10): temperatuur1.pop(0) luchtvochtigheid1.pop(0) if(cnt2>10): temperatuur2.pop(0) luchtvochtigheid2.pop(0) if(cnt3>10): temperatuur3.pop(0) luchtvochtigheid3.pop(0)