Pylab and pyserial plot in real time

Juho Schultz juho.schultz at helsinki.fi
Tue Nov 8 05:51:15 EST 2005


googlinggoogler at hotmail.com wrote:
> Hiya,
> 
> I've got a PIC microcontroller reading me humidity data via rs232, this
> is in ASCII format. I can view this data easily using hyperterminal or
> pyserial and convert it to its value (relative humidty with ord(input))
> 
> But what im trying to do is plot the data in real time, ideally with
> pylab - as it looks simple to use and simple is the way i want to go!
> 
This might be close to what you are trying to do:

import time
import pylab
# interactive mode on
pylab.ion()
timefig = pylab.figure(1)
timesub = pylab.subplot(111)
dt = 0.1
t = pylab.arange(0.0, 2.0, dt)
h = 1.2*pylab.sin(t)
lines = pylab.plot(t,h)
for i in range(8):
     t = t + dt
     h = 1.2*pylab.sin(t)
     lines[0].set_data(t,h)
     timesub.set_xlim((t[0],t[-1]))
     pylab.draw()
     time.sleep(1.0)

It shows a piece of sine curve, and updates the x-axis with time.



More information about the Python-list mailing list