0

I'm trying to generate a real time plot using Matplotlib, with real time gathered data from an Arduino MKR1000. Code:

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

ser = serial.Serial('COM7', 9600)
plt.close('all')
plt.figure(figsize=[10,8])
plt.ion()

data = np.array([])

while True:
    a = ser.readline()
    a = a.decode()
    b = float(a[0:4])
    data = np.append(data, b)
    plt.plot(data)
    plt.pause(0.1)

The output is a new plot created every 0.1 seconds, but I want to update the same real-time plot. Anyone can help? I'm using Python 3 on a Windows 10 system

Wang Liang
  • 4,244
  • 6
  • 22
  • 45

0 Answers0