我坚持我的密码。我想在PyQt5上有GUI来显示我的图形。我在matplot中有工作代码,但不能将其转换为PyQT。我是个初学者。我试图找到类似的代码,但我只做了这个。这在matplotlib上有效,但我希望在我的GUI上有它。在import serial
import numpy
import matplotlib.pyplot as plt
from drawnow import *
distance =[]
arduinoData=serial.Serial('COM4',115200)
plt.ion()
cnt=0
def makeFig():
plt.ylim(2,20)
plt.title('Plot ')
plt.grid(True)
plt.ylabel('Distance cm')
plt.plot(distance, 'ro-', label='Distance ')
plt.legend(loc='upper left')
while True: # While loop that loops forever
while (arduinoData.inWaiting()==0): #Wait here until there is data
pass #do nothing
arduinoString = arduinoData.readline() #read the line of text from the serial port
measurement = int(arduinoString) #Convert first element to floating number and put in measurement
distance.append(measurement) #Build our distance array by appending temp readings
drawnow(makeFig) #Call drawnow to update our live graph
plt.pause(.000001) #Pause Briefly. Important to keep drawnow from crashing
cnt=cnt+1
if(cnt>50): #If you have 50 or more points, delete the first one from the array
distance.pop(0) #This allows us to just see the last 50 data points
#This allows us to just see the last 50 data points
我的PyQt和Matplot。我想点击按钮显示这个图表。
我在第51行,在图中有一个错误
测量值=int(arduinoString)
ValueError:以10为基数的int()的文本无效:b'\n'“和
“后端TkAgg是交互式后端。打开交互模式。“
我从我的传感器发送简单距离的数据,比如5,10等等。在
^{pr2}$