仅作为记录,大佬请跳过。
直接上代码
import threading
import time
import numpy as np
from matplotlib.pyplot import *
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
# def print_111():
win = pg.GraphicsLayoutWidget(show=True)
win.setWindowTitle('pyqtgraph example: Scrolling Plots')
p2 = win.addPlot()
data1 = np.random.normal(size=300)
curve2 = p2.plot(data1)
ptr1 = 0
def update1():
global data1, ptr1
data1[:-1] = data1[1:] # shift data in the array one sample left
data1[-1] = np.random.normal()
ptr1 += 1
curve2.setData(data1)
curve2.setPos(ptr1, 0)
timer = pg.QtCore.QTimer()
timer.timeout.connect(update1)
timer.start(50)
# import sys
# if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
# QtGui.QApplication.instance().exec_()
# def print_111():
# import sys
#
# if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
# QtGui.QApplication.instance().exec_()
def print_222():
while 1:
print('222')
time.sleep(1)
threads = []
# t1 = threading.Thread(target=print_111)
# threads.append(t1)
t2 = threading.Thread(target=print_222)
threads.append(t2)
if __name__=='__main__':
import sys
for t in threads:
t.start()
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
for t in threads:
t.join()
print ("退出线程")
print('sec74')
展示:
参考