我正在尝试绘制服务器接收到的实时数据,同时我的 CPU(Windows XP 操作系统)的 RAM 内存增加,我从链接“ http://bazaar ”获取了 Luke-campagnola 所做的最新更新.launchpad.net/~luke-campagnola/pyqtgraph/inp/files/312/tools/debian/ "
提前感谢任何帮助或建议。
我在这里附上整个代码......
import sys
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
import collections
import random
import time
import math
import numpy as np
from pyqtgraph.ptime import time
class DynamicPlotter(QtGui.QWidget):
def __init__(self, parent = None):
QtGui.QWidget.__init__(self, parent)
sampleinterval=0.1
self.myvar = 0
self.prevdt=0
self.dt1 = 0
app = QtGui.QApplication([])
self.plot_param1 = []
self.plot_param2 = []
self.plot_param3 = []
self.plot_param4 = []
for g in range(0,100):
self.plot_param1.append(g/100)
self.plot_param2 .append((g+1)/100)
self.plot_param3.append(g/100)
self.plot_param4.append((g+1)/100)
self.samplesize = 100;
self.samples = range(0,self.samplesize)
for i in range(len(self.samples)):
self.samples[i] = self.samples[i]/100.0
self.framecount = 0;
pg.mkQApp()
self.pw = pg.PlotWidget()
self.pw.show()
self.p1 = self.pw.plotItem
self.p2 = pg.ViewBox()
self.p1.showAxis('right')
self.p1.scene().addItem(self.p2)
self.p2.setGeometry(self.p1.vb.sceneBoundingRect())
self.p1.getAxis('right').linkToView(self.p2)
self.p2.setXLink(self.p1)
self.pw.setLabel('bottom', 'Time in Secs')
self.pw.setLabel('left', 'Velocity in rpm')
self.pw.setLabel('right', 'load in Nm')
def update(self):
self.p1.plot(self.samples, self.plot_param3)
self.p2.addItem(self.p1.plot(self.samples, self.plot_param4, pen='b'))
self.dt1 = self.dt1+1
self.p1.setYRange(min(self.plot_param3), max(self.plot_param3))
self.p2.setXRange(self.dt1-1,self.dt1)
self.p2.setYRange(min(self.plot_param4), max(self.plot_param4))
if self.framecount == 0:
flushloop = self.samplesize
else:
flushloop = self.samplesize+1
for flush in range(1,flushloop):
self.samples.pop(0)
# below code is to prepare for next sample
self.framecount = self.framecount + 1
k=0
for update in range(self.framecount*self.samplesize,
self.framecount*self.samplesize+self.samplesize):
if(0):
self.plot_param1.append(self.framecount+(update/2))
self.plot_param2.append(self.framecount+ (update/2))
self.myvar=self.myvar-1
else:
self.myvar=self.myvar+1
#self.plot_param2.append(self.framecount+ (update/2))
#self.plot_param1.append(self.framecount+(update/2))
self.samples.append(update/100.0)
if(self.dt1<100):
self.plot_param1 = np.cos(np.linspace(0, 2*np.pi, 101))
self.plot_param3 = self.plot_param1.tolist()
self.plot_param2 = np.sin(np.linspace(0, 4*np.pi, 101))
self.plot_param4 = self.plot_param2.tolist()
if((self.dt1>=100)and (self.dt1 < 200)):
self.plot_param1 = np.cos(np.linspace(0, 20*np.pi, 101))
self.plot_param3 = self.plot_param1.tolist()
self.plot_param2 = np.sin(np.linspace(0, 40*np.pi, 101))
self.plot_param4 = self.plot_param2.tolist()
if((self.dt1>=200)and (self.dt1 < 300)):
for f in range(0,100):
self.plot_param1 = np.cos(np.linspace(0, 20*np.pi, 101))
self.plot_param3 = self.plot_param1.tolist()
#self.plot_param3.append(1+f)
self.plot_param2 = np.cos(np.linspace(0, 20*np.pi, 101))
#self.plot_param4.append(3+f)
self.plot_param4 = self.plot_param2.tolist()
if(self.dt1 >= 300):
self.plot_param1 = np.cos(np.linspace(0, 10*np.pi, 101))
self.plot_param3 = self.plot_param1.tolist()
self.plot_param2 = np.sin(np.linspace(0, 80*np.pi, 101))
self.plot_param4 = self.plot_param2.tolist()
for i in range (len(self.plot_param3)):
self.plot_param3[i] = 20 * self.plot_param3[i]
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = DynamicPlotter()
for i in range(0,100):
myapp.update()
timer = QtCore.QTimer()
timer.timeout.connect(myapp.update)
timer.start(50)