UtamaDonny

plotserial.py

Jun 11th, 2021
539
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # %%
  2. import time
  3. import serial
  4. import matplotlib.pyplot as plt
  5. from mpl_toolkits import mplot3d
  6.  
  7. ser=serial.Serial('COM4',115200)
  8.  
  9. dmxb= []
  10. dmyb= []
  11. dmzb= []
  12. dmzm= []
  13. dmym= []
  14. dmxm= []
  15. for i in range(100):
  16.   read=ser.readline()
  17.   if read :
  18.     decode=read.decode()
  19.     string=decode.strip()
  20.     split=string.split(',')
  21.     # rlb,ptb,ywb,gxb,gyb,gzb,l1b,l2b,l3b,mxb,myb,mzb,axb,ayb,azb,vxb,vyb,vzb,sys,gys,acs,mgs,axm,aym,azm,gxm,gym,gzm,mxm,mym,mzm=string.split(',')
  22.     rlb,ptb,ywb,gxb,gyb,gzb,\
  23.     l1b,l2b,l3b,mxb,myb,mzb,\
  24.     axb,ayb,azb,vxb,vyb,vzb,\
  25.     sys,gys,acs,mgs,axm,aym,\
  26.     azm,gxm,gym,gzm,mxm,mym,mzm\
  27.     =[float(x) for x in string.split(',')]
  28.     print(mxb)
  29.     dmxb.append(mxb)
  30.     print(myb)
  31.     dmyb.append(myb)
  32.     print(mzb)
  33.     dmzb.append(mzb)
  34.     print(mxm)
  35.     dmxm.append(mxm)
  36.     print(mym)
  37.     dmym.append(mym)
  38.     print(mzm)
  39.     dmzm.append(mzm)
  40. ser.close()
  41.  
  42. fig = plt.figure(figsize = (10, 7))
  43. ax = plt.axes(projection ="3d")
  44.  
  45. # Creating plot
  46. ax.scatter3D(mxb, myb, mzb, color = "green")
  47. plt.title("simple 3D scatter plot")
  48.  
  49. # show plot
  50. plt.show()
RAW Paste Data