コード例 #1
0
ファイル: angular_distr.py プロジェクト: jwerdec/beamerlib
class iScope(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.setWindowTitle("iScope (TM)")

        hlayout = QHBoxLayout()
        central_widget = QWidget(self)
        central_widget.setLayout(hlayout)
        self.setCentralWidget(central_widget)
        # ---guiqwt plot manager
        self.manager = PlotManager(self)
        # ---

    def add_plot(self, x, y):
        widget = iScopeWidget(self, x, y)
        widget.setup_widget()
        self.centralWidget().layout().addWidget(widget)
        # ---Register plot to manager
        self.manager.add_plot(widget.plot)
        # ---

    def setup_window(self):
        # ---Add toolbar and register manager tools
        toolbar = self.addToolBar("tools")
        self.manager.add_toolbar(toolbar, id(toolbar))
        self.manager.register_standard_tools()
        self.manager.tools[0].activate()
コード例 #2
0
ファイル: Car_Helper.py プロジェクト: Alsvr/SMART
def Plot_Start_New(widget,PLOT_DEFINE,COLORS,x1,x2,y1,y2):
    newmanager = PlotManager(widget)
    newplots = []
    newcurves = {}
    for name in PLOT_DEFINE:
            plot = CurvePlot()
            #设置图表颜色
            plot.setStyleSheet('''QWidget{   
                                                                border: 1px solid #32435E;   
                                                                border-radius: 3px;   
                                                                font-size:11pt;   
                                                                color:white;   
                                                                font-family:"Microsoft YaHei UI";  
                                                                /* padding: 0 8px; */  
                                                                background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,   
                                                                                             stop: 0 #080B10,   
                                                                                             stop: 1.0 #212C3F);   
                                                                selection-background-color: #0A246A;   
                                                            } '''  
                                         )
            plot.axisScaleDraw(CurvePlot.Y_LEFT).setMinimumExtent(20)
            newplots.append(plot)
            newmanager.add_plot(plot)
            plot.plot_id = id(plot)
            for curve_color, curve_name in map(None,COLORS,name):
                if  u"状态" in curve_name or  u"打角/100" in curve_name :
                    newcurves[curve_name] = guiqwt_make.curve([0], [0],markerfacecolor = 'black', markeredgecolor=curve_color, title=curve_name,marker = 'Diamond',linestyle = 'NoPen',markersize = 6)
                else:    
                    newcurves[curve_name] = guiqwt_make.curve([0], [0], color=curve_color, title=curve_name)
                
                plot.add_item(newcurves[curve_name])
            #设置X轴y轴
            plot.set_axis_limits(newcurves[curve_name].yAxis(),y1,y2)
            plot.set_axis_limits(newcurves[curve_name].xAxis(),x1,x2)
            plot.add_item(guiqwt_make.legend("BL"))
            
    
    newmanager.register_standard_tools()
    newmanager.get_default_tool().activate()
    return (newmanager,newplots,newcurves)
コード例 #3
0
class RealtimeDemo(QWidget):
    def __init__(self):
        super(RealtimeDemo, self).__init__()
        self.setWindowTitle(u"Realtime Demo")

        self.data = {u"t":array("d")}
        for name in sum(PLOT_DEFINE, []):
            self.data[name] = array("d")

        self.curves = {}
        self.t = 0
        vbox = QVBoxLayout()
        vbox.addWidget(self.setup_toolbar())
        self.manager = PlotManager(self)
        self.plots = []
        for i, define in enumerate(PLOT_DEFINE):
            plot = CurvePlot()
            plot.axisScaleDraw(CurvePlot.Y_LEFT).setMinimumExtent(60)
            self.manager.add_plot(plot)
            self.plots.append(plot)
            plot.plot_id = id(plot)
            for j, curve_name in enumerate(define):
                curve = self.curves[curve_name] = make.curve([0], [0], color=COLORS[j], title=curve_name)
                plot.add_item(curve)
            plot.add_item(make.legend("BL"))
            vbox.addWidget(plot)
        self.manager.register_standard_tools()
        self.manager.get_default_tool().activate()
        self.manager.synchronize_axis(CurvePlot.X_BOTTOM, self.manager.plots.keys())
        self.setLayout(vbox)
        self.startTimer(100)

    def setup_toolbar(self):
        toolbar = QToolBar()
        self.auto_yrange_checkbox = QCheckBox(u"Y-axis auto-adjust")
        self.auto_xrange_checkbox = QCheckBox(u"X-axis auto-adjust")
        self.xrange_box = QSpinBox()
        self.xrange_box.setMinimum(5)
        self.xrange_box.setMaximum(50)
        self.xrange_box.setValue(10)
        self.auto_xrange_checkbox.setChecked(True)        
        self.auto_yrange_checkbox.setChecked(True)
        toolbar.addWidget(self.auto_yrange_checkbox)
        toolbar.addWidget(self.auto_xrange_checkbox)        
        toolbar.addWidget(self.xrange_box)
        return toolbar

    def timerEvent(self, event):
        for i in range(100):
            t = self.t
            self.data[u"t"].append(t)
            self.data[u"sin1f"].append(sin(t))

            self.data[u"sin3f"].append(sin(3*t)/6)

            self.t += DT

        if self.auto_xrange_checkbox.isChecked():
            xmax = self.data["t"][-1]
            xmin = max(xmax - self.xrange_box.value(), 0)
        else:
            xmin, xmax = self.plots[0].get_axis_limits('bottom')

        for key, curve in self.curves.items():
            xdata = self.data["t"]
            ydata = self.data[key]
            x, y = get_peak_data(xdata, ydata, xmin, xmax, 600, 1/DT)
            curve.set_data(x, y)

        for plot in self.plots:
            if self.auto_yrange_checkbox.isChecked() and self.auto_xrange_checkbox.isChecked():
                plot.do_autoscale()
            elif self.auto_xrange_checkbox.isChecked():
                plot.set_axis_limits("bottom", xmin, xmax)
                plot.replot()
            else:
                plot.replot()
コード例 #4
0
ファイル: PlottingHelper.py プロジェクト: Toilet22/BPMonitor
class PlottingHelper(object):
	'''This is the class implementing the plotting work.'''
	def __init__(self, parent, signal_names, sample_rate):
		'''Do the initialization work.
		A PlottingHelper object helps plotting a group of signals all of which 
		has the same number of points to plot at one time.
		signal_names: 
			a dictionary {'list_name':['list of signal names']}
		sample_rate:
			the sample_rate of the signals
		'''

		self.sample_rate = sample_rate
		self.signal_names = signal_names
		self.curve_items = {}
		self.curve_plots = {}
		self.plot_manager = PlotManager(parent)

		for list_name, sig_name_list in self.signal_names.items():
			# One CurvePlot object for every sig_name_list
			curve_plot = CurvePlot()
			curve_plot.axisScaleDraw(CurvePlot.Y_LEFT).setMinimumExtent(10)
			self.curve_plots[list_name] = curve_plot
			curve_plot.plot_id = id(curve_plot)
			for i, sig_name in enumerate(sig_name_list):
				# One CurveItem object for every signal_name 
				print sig_name, colors[i]
				self.curve_items[sig_name] = make.curve([0], [0], \
					color=colors[i], title=sig_name)
				curve_plot.add_item(self.curve_items[sig_name])

			# add the curve_plot object to plot_manager
			self.plot_manager.add_plot(curve_plot) 

		# register and activate the tools 
		self.plot_manager.register_standard_tools()
		self.plot_manager.get_default_tool().activate()
		self.plot_manager.synchronize_axis(CurvePlot.X_BOTTOM, \
									self.plot_manager.plots.keys())

	def update_curves(self, time, signals, interval_in_second):	
		'''update the curves everytime the signals change
		time:
			the time sequence, which is also the x_axis data
		signal:
			a dictionary of signals to plot, the keys of which is recorded
			in self.signal_names.
			and in fact these are the y_axis data
		'''
		xmax = time[-1]
		xmin = max(xmax - interval_in_second, 0)
		xdata = time
		for list_name, sig_name_list in self.signal_names.items():
			# 
			for i, sig_name in enumerate(sig_name_list):
				# 
				ydata = signals[sig_name]
				idxmn = int(xmin*self.sample_rate)
				idxmx = int(xmax*self.sample_rate)
				self.curve_items[sig_name].set_data(xdata[idxmn:idxmx], \
													ydata[idxmn:idxmx])

			self.curve_plots[list_name].do_autoscale()
コード例 #5
0
class RealtimeDemo(QWidget):
    def __init__(self):
        super(RealtimeDemo, self).__init__()
        self.setWindowTitle(u"Realtime Demo")

        self.data = {u"t":array("d")}
        for name in sum(PLOT_DEFINE, []):
            self.data[name] = array("d")

        self.curves = {}
        self.t = 0
        vbox = QVBoxLayout()
        vbox.addWidget(self.setup_toolbar())
        self.manager = PlotManager(self)
        self.plots = []
        for i, define in enumerate(PLOT_DEFINE):
            plot = CurvePlot()
            plot.axisScaleDraw(CurvePlot.Y_LEFT).setMinimumExtent(60)
            self.manager.add_plot(plot)
            self.plots.append(plot)
            plot.plot_id = id(plot)
            for j, curve_name in enumerate(define):
                curve = self.curves[curve_name] = make.curve([0], [0], color=COLORS[j], title=curve_name)
                plot.add_item(curve)
            plot.add_item(make.legend("BL"))
            vbox.addWidget(plot)
        self.manager.register_standard_tools()
        self.manager.get_default_tool().activate()
        self.manager.synchronize_axis(CurvePlot.X_BOTTOM, self.manager.plots.keys())
        self.setLayout(vbox)
        self.startTimer(100)

    def setup_toolbar(self):
        toolbar = QToolBar()
        self.auto_yrange_checkbox = QCheckBox(u"Y轴自动调节")
        self.auto_xrange_checkbox = QCheckBox(u"X轴自动调节")
        self.xrange_box = QSpinBox()
        self.xrange_box.setMinimum(1)
        self.xrange_box.setMaximum(50)
        self.xrange_box.setValue(1)
        self.auto_xrange_checkbox.setChecked(True)        
        self.auto_yrange_checkbox.setChecked(True)
        toolbar.addWidget(self.auto_yrange_checkbox)
        toolbar.addWidget(self.auto_xrange_checkbox)        
        toolbar.addWidget(self.xrange_box)
        return toolbar

    def timerEvent(self, event):
        global bin_ori
        # writecache = []
        drawcache = []
        MAXRANGE = 65535
        AMPL = 6
        for i in range(n_channel):
            # writecache.append([])
            drawcache.append([])
        for i in range(collecttime):
            n = ser.inWaiting()
            # print(n)
            ori = ser.read(n)
            bin_ori += str(binascii.b2a_hex(ori))[2:-1]

        ffff_list = bin_ori.split('fffffffe')
        bin_ori = ffff_list[-1]
        wrong_no = 0
        # print(len(ffff_list))
        for i in range(1, len(ffff_list)):
            if len(ffff_list[i]) != 4 * n_channel:
                # print(i)
                # print('receive wrong')
                wrong_no += 1
                # print(ffff_list[i])
                continue

            for j in range(n_channel):
                temp = int(ffff_list[i][4 * j:4 * (j + 1)], 16)
                drawcache[j].append((temp))# - MAXRANGE / 2) / (MAXRANGE / 2) * AMPL)
                # writecache[j].append(str(temp))

        # print(wrong_no)
        # print(wrong_no / len(ffff_list))
        for i in xrange(len(drawcache[0])):
            t = self.t
            self.data[u"t"].append(t)
            # for j in xrange(n_channel):
            #     self.data[u"signal_"+str(j)].append(drawcache[j][i])
            # self.data[u"signal_0"].append(drawcache[0][i])
            self.data[u"signal_1"].append(drawcache[1][i])
            # self.data[u"signal_2"].append(drawcache[2][i])
            # self.data[u"signal_3"].append(drawcache[3][i])
            self.data[u"signal_4"].append(drawcache[4][i])
            # self.data[u"signal_5"].append(drawcache[5][i])
            # self.data[u"signal_6"].append(drawcache[6][i])
            self.data[u"signal_7"].append(drawcache[7][i])
            # self.data[u"signal_8"].append(drawcache[8][i])
            # self.data[u"signal_9"].append(drawcache[9][i])
            self.t += DT

        # for i in xrange(100):
        #     t = self.t
        #     self.data[u"t"].append(t)
        #     self.data[u"sin1f"].append(sin(t))
        #     self.data[u"cos1f"].append(cos(t))
        #     self.data[u"sin3f"].append(sin(3*t)/6)
        #     self.data[u"cos3f"].append(cos(3*t)/6)
        #     self.data[u"sin合成"].append(sin(t)+sin(3*t)/6)
        #     self.data[u"cos合成"].append(cos(t)+cos(3*t)/6)
        #     self.t += DT

        if self.auto_xrange_checkbox.isChecked():
            xmax = self.data["t"][-1]
            xmin = max(xmax - self.xrange_box.value(), 0)
        else:
            xmin, xmax = self.plots[0].get_axis_limits('bottom')

        for key, curve in self.curves.iteritems():
            xdata = self.data["t"]
            ydata = self.data[key]
            x, y = get_peak_data(xdata, ydata, xmin, xmax, 600, 1/DT)
            curve.set_data(x, y)

        for plot in self.plots:
            if self.auto_yrange_checkbox.isChecked() and self.auto_xrange_checkbox.isChecked():
                plot.do_autoscale()
            elif self.auto_xrange_checkbox.isChecked():
                plot.set_axis_limits("bottom", xmin, xmax)
                plot.replot()
            else:
                plot.replot()
コード例 #6
0
ファイル: qtgwtDemo.py プロジェクト: Liung/QAeroData
class RealtimeDemo(QWidget): 
    def __init__(self): 
        super(RealtimeDemo, self).__init__() 
        self.setWindowTitle(u"Realtime Demo") 
  
        self.data = {u"t": array("d")}
        for name in sum(PLOT_DEFINE, []): 
            self.data[name] = array("d") 
  
        self.curves = {} 
        self.t = 0 
        vbox = QVBoxLayout() 
        vbox.addWidget(self.setup_toolbar()) 
        self.manager = PlotManager(self) 
        self.plots = [] 
        for i, define in enumerate(PLOT_DEFINE): 
            plot = CurvePlot() 
            plot.axisScaleDraw(CurvePlot.Y_LEFT).setMinimumExtent(60) 
            self.manager.add_plot(plot) 
            self.plots.append(plot) 
            plot.plot_id = id(plot) 
            for j, curve_name in enumerate(define): 
                curve = self.curves[curve_name] = make.curve([0], [0], color=COLORS[j], title=curve_name) 
                plot.add_item(curve) 
            plot.add_item(make.legend("BL")) 
            vbox.addWidget(plot) 
        self.manager.register_standard_tools() 
        self.manager.get_default_tool().activate() 
        self.manager.synchronize_axis(CurvePlot.X_BOTTOM, self.manager.plots.keys()) 
        self.setLayout(vbox) 
        self.startTimer(100) 
  
    def setup_toolbar(self): 
        toolbar = QToolBar() 
        self.auto_yrange_checkbox = QCheckBox(u"Y轴自动调节") 
        self.auto_xrange_checkbox = QCheckBox(u"X轴自动调节") 
        self.xrange_box = QSpinBox() 
        self.xrange_box.setMinimum(5) 
        self.xrange_box.setMaximum(50) 
        self.xrange_box.setValue(10) 
        self.auto_xrange_checkbox.setChecked(True) 
        self.auto_yrange_checkbox.setChecked(True) 
        toolbar.addWidget(self.auto_yrange_checkbox) 
        toolbar.addWidget(self.auto_xrange_checkbox) 
        toolbar.addWidget(self.xrange_box) 
        return toolbar 
  
    def timerEvent(self, event): 
        for i in xrange(100): 
            t = self.t 
            self.data[u"t"].append(t) 
            self.data[u"sin1f"].append(sin(t)) 
            self.data[u"cos1f"].append(cos(t)) 
            self.data[u"sin3f"].append(sin(3*t)/6) 
            self.data[u"cos3f"].append(cos(3*t)/6) 
            self.data[u"sin合成"].append(sin(t)+sin(3*t)/6) 
            self.data[u"cos合成"].append(cos(t)+cos(3*t)/6) 
            self.t += DT 
  
        if self.auto_xrange_checkbox.isChecked(): 
            xmax = self.data["t"][-1] 
            xmin = max(xmax - self.xrange_box.value(), 0) 
        else: 
            xmin, xmax = self.plots[0].get_axis_limits('bottom') 
  
        for key, curve in self.curves.iteritems(): 
            xdata = self.data["t"] 
            ydata = self.data[key] 
            x, y = get_peak_data(xdata, ydata, xmin, xmax, 600, 1/DT) 
            curve.set_data(x, y) 
  
        for plot in self.plots: 
            if self.auto_yrange_checkbox.isChecked() and self.auto_xrange_checkbox.isChecked(): 
                plot.do_autoscale() 
            elif self.auto_xrange_checkbox.isChecked(): 
                plot.set_axis_limits("bottom", xmin, xmax) 
                plot.replot() 
            else: 
                plot.replot() 
コード例 #7
0
ファイル: 实时plot4.py プロジェクト: Nonikka/Quadcopter
class SyncXAxis(QtGui.QWidget):
    
    def __init__(self):
        super(SyncXAxis, self).__init__()
        
        self.data = {u"t":array("d")} 
        for name in sum(PLOT_DEFINE, []): 
            self.data[name] = array("d") 
        
        self.i = 0
        self.x = []
        self.curves = {} 
        self.t = 0
        self.sint = []
        self.get_Roll = []
        self.get_Pitch = []
        self.get_Yaw = []
        self.get_Angle1 = []
        self.get_Angle2 =[]
        self.get_Angle3 = []
        vbox = QtGui.QGridLayout()
        #工具栏
        vbox.addLayout(self.setup_toolbar(),0,0) 
        self.manager = PlotManager(self)
        self.plots = []
        #生成竖直排列图形窗口
        for i, define in enumerate(PLOT_DEFINE): 
            plot = CurvePlot() 
            plot.axisScaleDraw(CurvePlot.Y_LEFT).setMinimumExtent(60) 
            self.manager.add_plot(plot) 
            self.plots.append(plot) 
            plot.plot_id = id(plot) 
            for j, curve_name in enumerate(define): 
                curve = self.curves[curve_name] = make.curve([0], [0], color=COLORS[j], title=curve_name) 
                plot.add_item(curve) 
            plot.add_item(make.legend("BL")) 
            #vbox.addWidget(plot)
        vbox.addWidget(self.plots[0],1,0)
        vbox.addWidget(self.plots[1],1,1)
        vbox.addWidget(self.plots[2],2,0)
        vbox.addWidget(self.plots[3],2,1)
        
        self.manager.register_standard_tools()
        self.manager.get_default_tool().activate()
        self.manager.synchronize_axis(CurvePlot.X_BOTTOM, self.manager.plots.keys()) 
        self.setLayout(vbox)
        
        self.startTimer(20) 
        
    def setup_toolbar(self): 
        toolbar = QtGui.QGridLayout() 
        self.auto_xrange_checkbox = QtGui.QCheckBox(u"X轴自动调节") 
        self.xrange_box = QtGui.QSpinBox() 
        self.xrange_box.setMinimum(5) 
        self.xrange_box.setMaximum(100) 
        self.xrange_box.setValue(50) 
        self.auto_xrange_checkbox.setChecked(True) 
        
        self.Roll_label = QtGui.QLabel("PID KP:")
        self.lineEdit1 = QtGui.QLineEdit()
        self.lineEdit1.setText("1")
        self.lineEdit1.returnPressed.connect(self.PID_Roll)
        
        self.Roll_label.setBuddy(self.lineEdit1)
        self.Pitch_label = QtGui.QLabel("PID KI:")
        self.lineEdit2 = QtGui.QLineEdit()
        self.Pitch_label.setBuddy(self.lineEdit2)
        self.lineEdit2.setText("1")
        self.lineEdit2.returnPressed.connect(self.PID_Pitch)
        
        self.Yaw_label = QtGui.QLabel("PID KD:")
        self.lineEdit3 = QtGui.QLineEdit()
        self.Yaw_label.setBuddy(self.lineEdit3)
        self.lineEdit3.setText("1")
        self.lineEdit3.returnPressed.connect(self.PID_Yaw)
        
        toolbar.addWidget(self.auto_xrange_checkbox,0,0) 
        toolbar.addWidget(self.xrange_box,0,1) 
        toolbar.addWidget(self.Roll_label,1,0) 
        toolbar.addWidget(self.lineEdit1,1,1) 
        toolbar.addWidget(self.Pitch_label,2,0) 
        toolbar.addWidget(self.lineEdit2,2,1) 
        toolbar.addWidget(self.Yaw_label,3,0) 
        toolbar.addWidget(self.lineEdit3,3,1) 
        return toolbar 
        
    
    def PID_Roll(self):
        global RPY_Array
        try:
            #print str(int(self.lineEdit1.text()))
            RPY_Array[0] = int(self.lineEdit1.text())
        except:
            pass
            
    def PID_Pitch(self):
        global RPY_Array
        try:
            #print str(self.lineEdit1.text())
            RPY_Array[1] = int(self.lineEdit2.text())
        except:
            pass
            
    def PID_Yaw(self):
        global RPY_Array
        try:
            #print str(self.lineEdit1.text())
            RPY_Array[2] = int(self.lineEdit3.text())
        except:
            pass
        
    def timerEvent(self, event): 
        global RPY_Array,Roll,Pitch,Yaw,Angle1,Angle2,Angle3
        global xSlider,ySlider,zSlider
        self.x.append(self.t)
        self.t += DT 
        self.sint.append(np.sin(self.t))
        self.get_Roll.append(Roll)
        self.get_Pitch.append(Pitch)
        self.get_Yaw.append(Yaw)
        self.get_Angle1.append(Angle1)
        self.get_Angle2.append(Angle2)
        self.get_Angle3.append(Angle3)
        xSlider.setValue(Angle1 * 16)#初始值
        ySlider.setValue(Angle3 * 16)
        zSlider.setValue(Angle2 * 16)
        #x轴的移动
        if self.auto_xrange_checkbox.isChecked(): 
            xmax = self.x[-1] 
            xmin = self.xrange_box.value()
            if len(self.x) > xmin:
                
                self.x = self.x[-xmin:-1]
                self.get_Roll = self.get_Roll[-xmin:-1]
                self.get_Pitch = self.get_Pitch[-xmin:-1]
                self.get_Yaw = self.get_Yaw[-xmin:-1]
                self.get_Angle1 = self.get_Angle1[-xmin:-1]
                self.get_Angle2 = self.get_Angle2[-xmin:-1]
                self.get_Angle3 = self.get_Angle3[-xmin:-1]
        else :
            pass
        self.y_array = [[],[],[],[],[],[]]
        #3 最后一个
        #0 三
        #2 二
        self.y_array[2] = self.get_Roll
        self.y_array[0] = self.get_Pitch
        self.y_array[3] = self.get_Yaw
        self.y_array[1] = self.get_Angle1
        self.y_array[4] = self.get_Angle2
        self.y_array[5] = self.get_Angle3
        #print "\n",
        #print Roll,Pitch,Yaw,Angle1,Angle2,Angle3
        #发送PID参数
        global RPY_Array
        #serial_send(str("%04d" %RPY_Array[0]) + str("%04d" %RPY_Array[1]) + str("%04d" %RPY_Array[2]) + "111111")
        
        #更新数据 刷新图像
        self.i = 0
        for key, curve in self.curves.iteritems(): 
            #self.sint = self.sint + 1
            #self.sint = [x + 0.1 for x in self.sint]
            #print type(self.x),type(self.t)
            try:
                curve.set_data(self.x,self.y_array[self.i])
            except:
                pass
            #print self.i
            #print key
            self.i += 1
            
            
        for plot in self.plots: 
            if self.auto_xrange_checkbox.isChecked(): 
                plot.do_autoscale() 
            elif self.auto_xrange_checkbox.isChecked(): 
                plot.set_axis_limits("bottom", xmin, xmax) 
                plot.replot() 
            else: 
                plot.replot()