###現在のコード
Python
1import serial 2import numpy as np 3import time 4import matplotlib.pyplot as plt 5 6ser = serial.Serial("COM16", 9600, timeout = 0.1) 7print("Waiting for device") 8time.sleep(3) 9print(ser.name) 10 11#初期ダミーデータ 12t = np.zeros(100) 13y1 = np.zeros(100) 14 15plt.ion() 16plt.figure() 17 18li, = plt.plot(t, y1) 19plt.ylim(0,1023) 20plt.grid(True) 21 22while True: 23 try: 24 #シリアルデータを加工&print 25 input_data = ser.readline().decode().strip("") 26 data = input_data.split(",") 27 print(data) 28 29 #直近100データを用意 30 t = np.append(t, float(data[0])) 31 t = np.delete(t, 0) 32 y1 = np.append(y1, float(data[1])) 33 y1 = np.delete(y1, 0) 34 35 #データをセット 36 li.set_xdata(t) 37 li.set_ydata(y1) 38 plt.xlim(min(t), max(t)) 39 40 #描画 41 plt.draw() 42 plt.pause(0.001)
###やりたいこと
現在は[0],[1]のデータをプロットしているがさらに[2],[3]のデータもプロットしたい。
ご教授お願いします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。