def __init__(self, model, parent=None): super(VuePyQt, self).__init__() self.model = model self.setStyleSheet("background-color: #0f4c5c;") area = pyqtgraph.dockarea.DockArea() d1 = pyqtgraph.dockarea.Dock("Parameters", size=(1, 1)) d2 = pyqtgraph.dockarea.Dock("Plot", size=(500, 300), closable=False) area.addDock(d1, 'top') area.addDock(d2, 'bottom', d1) d1.label.setStyleSheet( "background-color:#0f4c5c;") # color falls back when moved d2.label.setStyleSheet( "background-color:#0f4c5c;") # color falls back when moved # create a Vertical layout layout = QVBoxLayout() self.setContentsMargins(0, 0, 0, 0) #self.setSpacing(0) # spent 3 days on this : https://stackoverflow.com/questions/2295290/what-do-lambda-function-closures-capture widgets = [] for key, value in model.params.items(): #print(key, value) # create slider if hasattr(value["min"], "value"): slider = QuantityQtSlider(value["min"], value["max"], value=value["value"], descr=key) else: slider = QuantityQtSlider(quantify(value["min"]), quantify(value["max"]), value=quantify(value["value"]), descr=key) # add slider to Vue setattr(self, key + "_slider", slider) # connect slider's value to model's value getattr(self, key + "_slider").qtslider.valueChanged.connect( lambda qtvalue, key=key: self.set_attr(self.model, key) ) #(lambda qtvalue:self.update_model_param_value(qtvalue, slider, key)) # make slider to update all curves #getattr(self, key+"_slider").qtslider.valueChanged.connect(lambda qtvalue:self.update_traces(qtvalue)) #print("make slider update dependent trace for", key) #print(" looping in curves") # make slider to update dependent traces for k, v in self.model.curves.items(): #print(" - curve ", k, v) base_deps = self.model.FLAT_DICT[v[0]] #print(" with deps", base_deps) if key in base_deps: #print(" key", key, "is in deps") #if key in v[1]: # loop over parameter list func = getattr(self.model, k) # func=func and k=k are mandatory see SO's 2295290 def _upd(qt_value, func=func, k=k): xs, ys = func() self.traces[k].setData(xs.value, ys.value) getattr(self, key + "_slider").qtslider.valueChanged.connect(_upd) #print("-------final setting", key) widgets.append(slider) # add widgets to the V layout, top to bottom for w in widgets: layout.addWidget(w) # layout.setAlignment(QtCore.Qt.AlignTop) # to remove margins layout.setContentsMargins(0, 0, 0, 0) #left top right bot # to remove space between each HBox layout.setSpacing(0) self.win = pg.GraphicsWindow(title="Basic plotting examples") #self.win.setStyleSheet("background-color: background-color: #6d6875;") self.canvas = self.win.addPlot( title="Plot11", row=1, col=1, ) # axisItems={"bottom":sp_xaxis}) self.canvas.setLabel('left', 'Y-axis Values') self.canvas.addLegend() self.canvas.showGrid(x=True, y=True) #self.canvas.se ("#6d6875") #self.canvas.setStyleSheet("background-color: background-color: #6d6875;") self.traces = dict() for name, all_deps in self.model.curves.items(): func_name = name #trace_dict["xys"] xs, ys = getattr(self.model, func_name)() pen_color = all_deps[-1] self.trace(name, xs, ys, pen=pen_color) # add the GraphicsWindow widget to the V layout #layout.addWidget(self.win) # since using a QMainWindow, we use a widget to set as central widget # and set the layout of this widget widget = QWidget() widget.setLayout(layout) d1.addWidget(widget) d2.addWidget(self.win) self.setCentralWidget(area)
def __init__(self): super().__init__() self.config = Config("redis_mdld.yaml") self.initiateKeyTypeName() self.setWindowTitle("均线") self.main_widget = QtWidgets.QWidget() # 创建一个主部件 self.main_layout = QtWidgets.QGridLayout() # 创建一个网格布局 self.main_widget.setLayout(self.main_layout) # 设置主部件的布局为网格 # self.setCentralWidget(self.main_widget) # 设置窗口默认部件 self.selection_widget = QtWidgets.QWidget() self.selection_layout = QtWidgets.QGridLayout() self.averagetype = QtWidgets.QLabel('均线类型') self.keynametype = QtWidgets.QLabel('均值类型') self.keytype = QtWidgets.QLabel('行情类型') self.scaletype = QtWidgets.QLabel('缩放比例10^') self.movingType = QtWidgets.QLabel("平移距离") self.nbox = 5 self.select_box_list = list() #> (QComboBox,QComboBox1,QComboBox2) self.data_list = list() #> list() self.time_list = list() #> list() for i in range(self.nbox): self.data_list.append(list()) for i in range(self.nbox): self.time_list.append(list()) for i in range(self.nbox): t = QtWidgets.QComboBox() t.addItems(self.averageNames) t1 = QtWidgets.QComboBox() t1.addItems(self.keyTypeName) t2 = QtWidgets.QComboBox() t2.addItems(self.keyNames) color = self.colortype[i] label = QtWidgets.QLabel() label.setAutoFillBackground(True) palette = QtGui.QPalette() palette.setColor(QtGui.QPalette.Window, color) label.setPalette(palette) label2 = QtWidgets.QLabel() label2.setText("None") # t3 = QtWidgets.QComboBox() # t3.addItems(self.scale) s = QtWidgets.QSpinBox() s.setRange(0,100) s.setSingleStep(1) s1 = QtWidgets.QDoubleSpinBox() s1.setRange(-10.0,10.0) s1.setSingleStep(0.1) self.select_box_list.append((t,t1,t2,label,label2,s,s1)) self.selection_widget.setLayout(self.selection_layout) self.selection_layout.addWidget(self.averagetype, 0, 0, 1, 1) self.selection_layout.addWidget(self.keytype, 0, 1, 1, 1) self.selection_layout.addWidget(self.keynametype, 0, 2, 1, 1) self.selection_layout.addWidget(self.scaletype,0,5,1,1) self.selection_layout.addWidget(self.movingType,0,6,1,1) for i in range(self.nbox): self.selection_layout.addWidget(self.select_box_list[i][0],i+1,0,1,1) self.selection_layout.addWidget(self.select_box_list[i][1],i+1,1,1,1) self.selection_layout.addWidget(self.select_box_list[i][2],i+1,2,1,1) self.selection_layout.addWidget(self.select_box_list[i][3],i+1,3,1,1) self.selection_layout.addWidget(self.select_box_list[i][4],i+1,4,1,1) self.selection_layout.addWidget(self.select_box_list[i][5],i+1,5,1,1) self.selection_layout.addWidget(self.select_box_list[i][6],i+1,6,1,1) self.main_layout.addWidget(self.selection_widget,0,0,1,1) self.plot_widget = QtWidgets.QWidget() # 实例化一个widget部件作为K线图部件 self.plot_layout = QtWidgets.QGridLayout() # 实例化一个网格布局层 self.plot_widget.setLayout(self.plot_layout) # 设置K线图部件的布局层 # self.plot_plt = pg.PlotWidget() # 实例化一个绘图部件 self.plot_plt2 = pg.GraphicsWindow(title="画图") self.time_axis = {37800:"09:30:00", 45000:"11:30:00/13:00:00", 45000+7200:"15:00:00"} self.stringaxis = pg.AxisItem(orientation='bottom') self.stringaxis.setTicks([self.time_axis.items()]) self.plot_plt = self.plot_plt2.addPlot(axisItems={'bottom':self.stringaxis}) self.plot_plt.showGrid(x=True, y=True) # 显示图形网格 self.plot_layout.addWidget(self.plot_plt2) # 添加绘图部件到K线图部件的网格布局层 # 将上述部件添加到布局层中 self.main_layout.addWidget(self.plot_widget, 1, 0, 1, 1) # self.main_layout.addWidget(self.combobox_1,4,3,3,4) # self.main_layout.addWidget(self.combobox_2,7,4,4,4) self.setCentralWidget(self.main_widget) self.plot_plt.setYRange(max=10, min=0) self.plot_plt.setXRange(0,60*60*24,padding=0) self.plot_plt.setLabel(axis='left',text = '数据') self.plot_plt.setLabel(axis='bottom',text='时间') # self.plot_plt.lockXRange() self.conn_r = redis.Redis(host="192.168.40.134", port=6379, password="", charset='gb18030', errors="replace", decode_responses=True) self.currentDate = str(time.localtime().tm_year) + "-" + str(time.localtime().tm_mon) + "-" + str(time.localtime().tm_mday) #> "2019-07-11" self.plt_list = list() for i in range(self.nbox): self.plt_list.append(self.plot_plt.plot()) self.last_name = list() for i in range(self.nbox): self.last_name.append([None,None,None,None,None]) self.timer_start()
# -*- coding: utf-8 -*- """ This example shows all the scatter plot symbols available in pyqtgraph. These symbols are used to mark point locations for scatter plots and some line plots, similar to "markers" in matplotlib and vispy. """ from pyqtgraph.Qt import QtGui, QtCore import pyqtgraph as pg app = QtGui.QApplication([]) win = pg.GraphicsWindow(title="Scatter Plot Symbols") win.resize(1000, 600) pg.setConfigOptions(antialias=True) plot = win.addPlot(title="Plotting with symbols") plot.addLegend() plot.plot([0, 1, 2, 3, 4], pen=(0, 0, 200), symbolBrush=(0, 0, 200), symbolPen='w', symbol='o', symbolSize=14, name="symbol='o'") plot.plot([1, 2, 3, 4, 5], pen=(0, 128, 0), symbolBrush=(0, 128, 0), symbolPen='w', symbol='t',
def __init__(self, bufferPeek, sampleCLK=2E6, numChannels=4, refreshRate=10, bufferDepth=10, dummy=False, dummyData=None): # mp.Process.__init__(self); self._numChannels = numChannels self._refreshPeriod = 1.0 / refreshRate self._bufferSize = bufferDepth * refreshRate + 1 self._bufferSizeBeta = 30 * 60 * refreshRate + 1 self._sampleCLK = sampleCLK self._peeker = bufferPeek self.dummy = dummy self.dummyData = None self.dataPayloadSize = None self.tauSize = None if (self.dummy): self.dummyData = open(dummyData, 'rb') self.dataPayloadSize = int(self._sampleCLK * self._refreshPeriod) else: try: self.dataPayloadSize = int( len(self._peeker.get(block=True, timeout=1))) except Exception as e: print("HARDWARE ERROR") raise (e) self.tauSize = len( G2Calc.mtAuto(np.ones([int(self.dataPayloadSize / 2) - 1]), fs=self._sampleCLK, levels=16)[1:, 0]) # print(self.tauSize); #self._lastTime = time.time(); #SET UP WINDOW self.win = pg.GraphicsWindow() self.win.setWindowTitle("G2 Display") #SET UP PLOTS self.g2Plot = self.win.addPlot(title='G2') self.g2Plot.setLabel('bottom', 'tau', 's') self.g2Plot.setLabel('left', 'G2') self.g2Plot.setMouseEnabled(x=False, y=False) self.g2Plot.enableAutoRange(x=False, y=False) self.g2Plot.setLogMode(x=True, y=False) self.g2Plot.setYRange(0.9, 1.6) self.win.nextCol() self.countPlot = self.win.addPlot(title='Photon Count') self.countPlot.setLabel('bottom', 'Time', 's') self.countPlot.setLabel('left', 'count', 'cps') self.countPlot.setLabel('right', 'count', 'cps') self.countPlot.setMouseEnabled(x=False, y=False) self.countPlot.enableAutoRange(x=True, y=True) self.win.nextRow() self.snrPlot = self.win.addPlot(title='SNR') self.snrPlot.setLabel('bottom', 'tau', 's') self.snrPlot.setLabel('left', 'SNR') self.snrPlot.setMouseEnabled(x=False, y=False) self.snrPlot.enableAutoRange(x=False, y=True) self.snrPlot.setLogMode(x=True, y=False) # self.snrPlot.setYRange(0.9, 1.6); self.win.nextCol() self.betaPlot = self.win.addPlot(title="Beta") self.betaPlot.setLabel('bottom', 'Time', 'min') self.betaPlot.setMouseEnabled(x=False, y=False) self.betaPlot.enableAutoRange(x=True, y=True) #SET UP CONSTANTS self.xVals = np.linspace(-1 * bufferDepth, 0, self._bufferSize) self.xValsBeta = np.linspace(-1 * 30, 0, self._bufferSizeBeta) #SET UP DATA STRUCTURES # self.g2PlotData = []; self.snrPlotData = [] self.countPlotData = [] self.betaPlotData = [] #SET UP PLOT CURVES self.g2Curve = [] self.snrCurve = [] self.countCurve = [] self.betaCurve = [] #LOAD INITIAL DATA for c in range(self._numChannels): # self.g2PlotData.append(np.array([])); self.snrPlotData.append(np.zeros([self._bufferSize, self.tauSize])) self.countPlotData.append(np.zeros(self._bufferSize)) self.betaPlotData.append(np.zeros(self._bufferSizeBeta)) self.g2Curve.append( self.g2Plot.plot(x=[1], y=[1], pen=G2GraphWindow.penColors[c])) self.snrCurve.append( self.snrPlot.plot(x=[1], y=[1], pen=G2GraphWindow.penColors[c])) self.countCurve.append( self.countPlot.plot(x=self.xVals, y=self.countPlotData[c], pen=G2GraphWindow.penColors[c])) self.betaCurve.append( self.betaPlot.plot(x=self.xValsBeta, y=self.betaPlotData[c], pen=G2GraphWindow.penColors[c])) self.circularCounter = 0 self._timer = pg.QtCore.QTimer() self._retryCount = 0 self._isAlive = True self.win.closeEvent = self.closeEvent return
""" import initExample ## Add path to library (just for examples; you do not need this) from optics import * import pyqtgraph as pg import numpy as np from pyqtgraph import Point app = pg.QtGui.QApplication([]) w = pg.GraphicsWindow(border=0.5) w.resize(1000, 900) w.show() ### Curved mirror demo view = w.addViewBox() view.setAspectLocked() #grid = pg.GridItem() #view.addItem(grid) view.setRange(pg.QtCore.QRectF(-50, -30, 100, 100)) optics = [] rays = [] m1 = Mirror(r1=-100, pos=(5, 0), d=5, angle=-15) optics.append(m1)
# nicer colors seaborn_deep = [ "#4C72B0", "#DD8452", "#55A868", "#C44E52", "#8172B3", "#937860", "#DA8BC3", "#8C8C8C", "#CCB974", "#64B5CD" ] color_bg = pg.mkColor("#eaeaf2") color_curves = [] for color in seaborn_deep: color_curves.append(pg.mkColor(color)) ################################################################################ # set-up Qt plot window app = QtGui.QApplication([]) win = pg.GraphicsWindow(title='Position Estimation Demo') win.resize(800, 600) win.move(100, 100) win.setWindowTitle('pyqtgraph example: Plotting') win.setBackground('w') pg.setConfigOptions(antialias=True) pg.setConfigOption('foreground', 'k') ################################################################################ def update_plots(): global acc_curve, acc_data, gyro_curve, gyro_data, origin, cube, view try: ser_line = ser.readline()
# Import libraries from numpy import * from pyqtgraph.Qt import QtGui, QtCore import pyqtgraph as pg import serial # Create object serial port portName = '/dev/ttyUSB0' # replace this port name by yours! baudrate = 9600 ser = serial.Serial(portName, baudrate) ### START QtApp ##### app = QtGui.QApplication([]) # you MUST do this once (initialize things) #################### win = pg.GraphicsWindow(title="Signal from serial port") # creates a window p = win.addPlot(title="Realtime plot") # creates empty space for the plot in the window curve = p.plot() # create an empty "plot" (a curve to plot) windowWidth = 500 # width of the window displaying the curve Xm = linspace(0, 0, windowWidth) # create array that will contain the relevant time series ptr = -windowWidth # set first x position # Realtime data plot. Each time this function is called, the data display is updated def update(): global curve, ptr, Xm Xm[:-1] = Xm[1:] # shift data in the temporal mean 1 sample left value = ser.readline() # read line (single value) from the serial port Xm[-1] = float(value) # vector containing the instantaneous values ptr += 1 # update x position for displaying the curve
if len(sys.argv) < 2: print("Usage: " + sys.argv[0] + " file") exit(1) filename = sys.argv[1] print("Reading " + filename) x0 = np.array([]) x1 = np.array([]) x2 = np.array([]) x3 = np.array([]) app = QtGui.QApplication([]) win = pg.GraphicsWindow(title="Draw dump") win.resize(1000, 600) win.setWindowTitle('pyqtgraph app') pg.setConfigOptions(antialias=True) p0 = win.addPlot(col=0, row=0, title="Plot0") p1 = win.addPlot(col=0, row=1, title="Plot1") p2 = win.addPlot(col=0, row=2, title="Plot2") p3 = win.addPlot(col=0, row=3, title="Plot3") w0 = p0.plot(pen='r') w1 = p1.plot(pen='g') w2 = p2.plot(pen='b') w3 = p3.plot(pen='y') state = 0 data = []
def _qtg_plot_signal(G, signal, edges, vertex_size, limits, title): qtg, gl, QtGui = _import_qtg() if G.coords.shape[1] == 2: window = qtg.GraphicsWindow(title) view = window.addViewBox() elif G.coords.shape[1] == 3: if not QtGui.QApplication.instance(): QtGui.QApplication([]) # We want only one application. widget = gl.GLViewWidget() widget.opts['distance'] = 10 widget.show() widget.setWindowTitle(title) if edges: if G.coords.shape[1] == 2: adj = _get_coords(G, edge_list=True) pen = tuple(np.array(G.plotting['edge_color']) * 255) g = qtg.GraphItem(pos=G.coords, adj=adj, symbolBrush=None, symbolPen=None, pen=pen) view.addItem(g) elif G.coords.shape[1] == 3: x, y, z = _get_coords(G) pos = np.stack((x, y, z), axis=1) g = gl.GLLinePlotItem(pos=pos, mode='lines', color=G.plotting['edge_color']) widget.addItem(g) pos = [1, 8, 24, 40, 56, 64] color = np.array([[0, 0, 143, 255], [0, 0, 255, 255], [0, 255, 255, 255], [255, 255, 0, 255], [255, 0, 0, 255], [128, 0, 0, 255]]) cmap = qtg.ColorMap(pos, color) signal = 1 + 63 * (signal - limits[0]) / limits[1] - limits[0] if G.coords.shape[1] == 2: gp = qtg.ScatterPlotItem(G.coords[:, 0], G.coords[:, 1], size=vertex_size / 10, brush=cmap.map(signal, 'qcolor')) view.addItem(gp) if G.coords.shape[1] == 3: gp = gl.GLScatterPlotItem(pos=G.coords, size=vertex_size / 3, color=cmap.map(signal, 'float')) widget.addItem(gp) if G.coords.shape[1] == 2: global _qtg_windows _qtg_windows.append(window) elif G.coords.shape[1] == 3: global _qtg_widgets _qtg_widgets.append(widget)
# Import libraries import numpy as np from pyqtgraph.Qt import QtGui, QtCore import pyqtgraph as pg ### START QtApp ##### app = QtGui.QApplication([]) # you MUST do this once (initialize things) win = pg.GraphicsWindow( title="Signal from potomultiplier and photodiode") # creates a window win.showMaximized() p = win.addPlot( title="Photomuliplier") # creates empty space for the plot in the window curve = p.plot() # create an empty "plot" (a curve to plot) windowWidth = 500 # width of the window displaying the curve Xm = np.linspace( 0, 0, windowWidth) # create array that will contain the relevant time series ptr = -windowWidth ## second windowm-> code here p2 = win.addPlot( title="Photodiode (VIS)") # creates empty space for the plot in the window curve2 = p2.plot() # create an empty "plot" (a curve to plot) Xm2 = np.linspace( 0, 0, windowWidth) # create array that will contain the relevant time series ptr2 = -windowWidth
def setupUi(self, MainWindow): MainWindow.setObjectName("Variant 7 VS") MainWindow.resize(696, 498) pq.setConfigOption('background', 'w') pq.setConfigOption('foreground', 'k') self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.gridLayout_2 = QtWidgets.QGridLayout(self.centralwidget) self.gridLayout_2.setObjectName("gridLayout_2") self.err_tab = QtWidgets.QTabWidget(self.centralwidget) self.err_tab.setObjectName("err_tab") self.mainplottab_tab = QtWidgets.QWidget() self.mainplottab_tab.setObjectName("mainplottab_tab") self.groupBox = QtWidgets.QGroupBox(self.mainplottab_tab) self.groupBox.setGeometry(QtCore.QRect(0, 0, 81, 171)) self.groupBox.setTitle("") self.groupBox.setObjectName("groupBox") self.n_line = QtWidgets.QLineEdit(self.groupBox) self.n_line.setGeometry(QtCore.QRect(30, 110, 31, 20)) self.n_line.setObjectName("n_line") self.n_line.setText("100") self.x0_line = QtWidgets.QLineEdit(self.groupBox) self.x0_line.setGeometry(QtCore.QRect(30, 10, 31, 20)) self.x0_line.setObjectName("x0_line") self.x0_line.setText("1") self.xf_line = QtWidgets.QLineEdit(self.groupBox) self.xf_line.setGeometry(QtCore.QRect(30, 40, 31, 20)) self.xf_line.setObjectName("xf_line") self.xf_line.setText("18.2") self.y0_line = QtWidgets.QLineEdit(self.groupBox) self.y0_line.setGeometry(QtCore.QRect(30, 70, 31, 20)) self.y0_line.setObjectName("y0_line") self.y0_line.setText("3") self.label = QtWidgets.QLabel(self.groupBox) self.label.setGeometry(QtCore.QRect(10, 10, 21, 21)) self.label.setObjectName("label") self.label_2 = QtWidgets.QLabel(self.groupBox) self.label_2.setGeometry(QtCore.QRect(10, 40, 16, 21)) self.label_2.setObjectName("label_2") self.label_3 = QtWidgets.QLabel(self.groupBox) self.label_3.setGeometry(QtCore.QRect(10, 70, 20, 21)) self.label_3.setObjectName("label_3") self.label_4 = QtWidgets.QLabel(self.groupBox) self.label_4.setGeometry(QtCore.QRect(10, 110, 20, 21)) self.label_4.setObjectName("label_4") self.line = QtWidgets.QFrame(self.groupBox) self.line.setGeometry(QtCore.QRect(0, 90, 71, 16)) self.line.setFrameShape(QtWidgets.QFrame.HLine) self.line.setFrameShadow(QtWidgets.QFrame.Sunken) self.line.setObjectName("line") self.showNplots_button = QtWidgets.QPushButton(self.groupBox) self.showNplots_button.setGeometry(QtCore.QRect(14, 140, 51, 23)) self.showNplots_button.setObjectName("showNplots_button") self.plots = QtWidgets.QTabWidget(self.mainplottab_tab) self.plots.setGeometry(QtCore.QRect(80, 0, 591, 411)) self.plots.setObjectName("plots") self.solPlots_tab = QtWidgets.QWidget() self.solPlots_tab.setObjectName("solPlots_tab") self.gridLayout = QtWidgets.QGridLayout(self.solPlots_tab) self.gridLayout.setObjectName("gridLayout") self.plot_numerical = pq.GraphicsWindow(parent=self.solPlots_tab) self.plot_numerical.setObjectName("plot_numerical") self.gridLayout.addWidget(self.plot_numerical, 0, 0, 1, 1) self.plots.addTab(self.solPlots_tab, "") self.LE_tab = QtWidgets.QWidget() self.LE_tab.setObjectName("LE_tab") self.gridLayout_3 = QtWidgets.QGridLayout(self.LE_tab) self.gridLayout_3.setObjectName("gridLayout_3") self.le_win = pq.GraphicsWindow(parent=self.err_tab) self.gridLayout_3.addWidget(self.le_win, 0, 0, 1, 1) self.plots.addTab(self.LE_tab, "") self.err_tab.addTab(self.mainplottab_tab, "") self.GE_tab = QtWidgets.QWidget() self.GE_tab.setObjectName("GE_tab") self.groupBox_2 = QtWidgets.QGroupBox(self.GE_tab) self.groupBox_2.setGeometry(QtCore.QRect(0, 0, 81, 101)) self.groupBox_2.setTitle("") self.groupBox_2.setObjectName("groupBox_2") self.n0_line = QtWidgets.QLineEdit(self.groupBox_2) self.n0_line.setGeometry(QtCore.QRect(30, 10, 31, 20)) self.n0_line.setObjectName("n0_line") self.n0_line.setText("20") self.N_line = QtWidgets.QLineEdit(self.groupBox_2) self.N_line.setGeometry(QtCore.QRect(30, 40, 31, 20)) self.N_line.setObjectName("N_line") self.N_line.setText("200") self.label_5 = QtWidgets.QLabel(self.groupBox_2) self.label_5.setGeometry(QtCore.QRect(10, 10, 21, 21)) self.label_5.setObjectName("label_5") self.label_6 = QtWidgets.QLabel(self.groupBox_2) self.label_6.setGeometry(QtCore.QRect(10, 40, 16, 21)) self.label_6.setObjectName("label_6") self.showGE_button = QtWidgets.QPushButton(self.groupBox_2) self.showGE_button.setGeometry(QtCore.QRect(10, 70, 51, 23)) self.showGE_button.setObjectName("showLE_button") self.ge_win = pq.GraphicsWindow(parent=self.GE_tab) self.ge_win.setGeometry(QtCore.QRect(90, 20, 571, 371)) self.ge_win.setObjectName("plot_ge") self.err_tab.addTab(self.GE_tab, "") self.gridLayout_2.addWidget(self.err_tab, 0, 0, 1, 1) MainWindow.setCentralWidget(self.centralwidget) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.plot_numtab() self.plot_getab() self.showNplots_button.clicked.connect(self.plot_numtab) self.showGE_button.clicked.connect(self.plot_getab) self.retranslateUi(MainWindow) self.err_tab.setCurrentIndex(0) self.plots.setCurrentIndex(0) QtCore.QMetaObject.connectSlotsByName(MainWindow)
# -*- coding: utf8 -*- __author__ = 'Clemens Prescher' import pyqtgraph as pg from pyqtgraph.exporters.SVGExporter import SVGExporter from PyQt4 import QtGui if __name__ == '__main__': app = QtGui.QApplication([]) win = pg.GraphicsWindow("title SVG Exporter bug") win.resize(1000, 600) p1 = win.addPlot() p1.plot(x=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], y=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], pen=(200, 200, 200), symbolBrush=(255, 0, 0), symbolPen='w') QtGui.QApplication.processEvents() QtGui.QApplication.processEvents() exporter = SVGExporter(p1) exporter.export("test.svg")
def __init__(self): self.c1 = True self.c2 = True self.cd1 = True self.cd2 = True self.lectura1 = True self.pch1=[] self.pch2=[] self.pchd1=[] self.pchd2=[] self.traces= dict() self.t= np.arange(0, 1, 1/2000) pg.setConfigOptions(antialias=True) self.app=QtGui.QApplication(sys.argv) self.win=pg.GraphicsWindow() self.win.resize(1000,600) self.win.setWindowTitle('pyqtgraph example') n = 1 m = 1 axisY = [(0,'0'),(m*1,'1'),(m*2,'2'),(m*3,'3'),(m*4,'4')] self.CaxisY = pg.AxisItem(orientation='left') self.CaxisY.setTicks([axisY]) self.Canvas = self.win.addPlot(row=0,col=0,colspan=4,title="Osciloscopio",axisItems={'left':self.CaxisY}) self.Canvas.showGrid(x=True,y=True, alpha = 0.5) self.Canvas.setYRange(0, m*4, 0) self.Canvas.setXRange(0, 1*n, 0) self.Canvas.hideButtons() self.Canvas.invertX(b=True) #BOTONES #Botones de Amplitud proxy1 = QtGui.QGraphicsProxyWidget() button1 = QtGui.QPushButton('0.3 V/div') proxy1.setWidget(button1) self.V03 = self.win.addLayout(row=3, col=1) self.V03.addItem(proxy1,row=0,col=0) button1.clicked.connect(self.Vt03) proxy2 = QtGui.QGraphicsProxyWidget() button2 = QtGui.QPushButton('1 V/div') proxy2.setWidget(button2) self.V1 = self.win.addLayout(row=3, col=2) self.V1.addItem(proxy2,row=0,col=0) button2.clicked.connect(self.Vt1) proxy3 = QtGui.QGraphicsProxyWidget() button3 = QtGui.QPushButton('3 V/div') proxy3.setWidget(button3) self.V3 = self.win.addLayout(row=3, col=3) self.V3.addItem(proxy3,row=0,col=0) button3.clicked.connect(self.Vt3) #Botones de frecuencia proxy4 = QtGui.QGraphicsProxyWidget() button4 = QtGui.QPushButton('10 Hz') proxy4.setWidget(button4) self.f10 = self.win.addLayout(row=4, col=1) self.f10.addItem(proxy4,row=0,col=0) button4.clicked.connect(self.fq10) proxy5 = QtGui.QGraphicsProxyWidget() button5 = QtGui.QPushButton('100 Hz') proxy5.setWidget(button5) self.f100 = self.win.addLayout(row=4, col=2) self.f100.addItem(proxy5,row=0,col=0) button5.clicked.connect(self.fq100) proxy6 = QtGui.QGraphicsProxyWidget() button6 = QtGui.QPushButton('1 kHz') proxy6.setWidget(button6) self.f1k = self.win.addLayout(row=4, col=3) self.f1k.addItem(proxy6,row=0,col=0) button6.clicked.connect(self.fq1k) proxy11 = QtGui.QGraphicsProxyWidget() button11 = QtGui.QPushButton('1 Hz') proxy11.setWidget(button11) self.f1 = self.win.addLayout(row=2, col=2) self.f1.addItem(proxy11,row=0,col=0) button11.clicked.connect(self.fq1) """self.label1=self.win.addLayout(row=1,col=2) self.label1.addLabel(text='Selector de Canales',row=0,col=0) self.label2=self.win.addLayout(row=3,col=0) self.label2.addLabel(text='Selector de Amplitud',row=0,col=0) self.label3=self.win.addLayout(row=4,col=0) self.label3.addLabel(text='Selector de base de tiempo',row=0,col=0)""" #Botones de canales proxy7 = QtGui.QGraphicsProxyWidget() button7 = QtGui.QPushButton('Channel 1') proxy7.setWidget(button7) self.channel1 = self.win.addLayout(row=1, col=1) self.channel1.addItem(proxy7,row=0,col=0) button7.clicked.connect(self.chn1) proxy8 = QtGui.QGraphicsProxyWidget() button8 = QtGui.QPushButton('Channel 2') proxy8.setWidget(button8) self.channel2 = self.win.addLayout(row=1, col=3) self.channel2.addItem(proxy8,row=0,col=0) button8.clicked.connect(self.chn2) proxy9 = QtGui.QGraphicsProxyWidget() button9 = QtGui.QPushButton('ChannelD 1') proxy9.setWidget(button9) self.channeld1 = self.win.addLayout(row=2, col=1) self.channeld1.addItem(proxy9,row=0,col=0) button9.clicked.connect(self.chnd1) proxy10 = QtGui.QGraphicsProxyWidget() button10 = QtGui.QPushButton('ChannelD 2') proxy10.setWidget(button10) self.channeld2 = self.win.addLayout(row=2, col=3) self.channeld2.addItem(proxy10,row=0,col=0) button10.clicked.connect(self.chnd2)
def _main(): app = QtGui.QApplication([]) win = pg.GraphicsWindow(title="Steam Controller") win.resize(1000, 600) win.nextRow() p1 = win.addPlot(name="plot1", title='Pitch') win.nextColumn() p2 = win.addPlot(name="plot2", title='Roll') p2.setYLink("plot1") win.nextColumn() p3 = win.addPlot(name="plot3", title='Yaw') p3.setYLink("plot1") win.nextRow() p4 = win.addPlot(name="plot4", title='Others', colspan=5) win.nextRow() p1.addLegend() p1.showGrid(x=True, y=True, alpha=0.5) p1.setYRange(-8000, 8000) p2.addLegend() p2.showGrid(x=True, y=True, alpha=0.5) p2.setYRange(-8000, 8000) p3.addLegend() p3.showGrid(x=True, y=True, alpha=0.5) p3.setYRange(-8000, 8000) p4.addLegend() p4.showGrid(x=True, y=True, alpha=0.5) p4.setYRange(-32767, 32767) imu = { 'gpitch': [], 'groll': [], 'gyaw': [], 'q1': [], 'q2': [], 'q3': [], 'q4': [], } curves = { 'gpitch': p1.plot(times, [], pen=(0, 2), name='vel'), 'groll': p2.plot(times, [], pen=(0, 2), name='vel'), 'gyaw': p3.plot(times, [], pen=(0, 2), name='vel'), 'q1': p4.plot(times, [], pen=(0, 4), name='1'), 'q2': p4.plot(times, [], pen=(1, 4), name='2'), 'q3': p4.plot(times, [], pen=(2, 4), name='3'), 'q4': p4.plot(times, [], pen=(3, 4), name='4'), } def update(sc, sci): global times if sci.status != 15361: return cur = time.time() times.append(cur) times = [x for x in times if cur - x <= 10.0] for name in imu.keys(): imu[name].append(sci._asdict()[name]) nt = len(times) ni = len(imu[name]) if nt < ni: imu[name] = imu[name][-nt:] elif nt > ni: times = times[nt - ni:] curves[name].setData(times, imu[name]) app.processEvents() sc = SteamController(callback=update) sc.handleEvents() sc._sendControl( struct.pack('>' + 'I' * 6, 0x87153284, 0x03180000, 0x31020008, 0x07000707, 0x00301400, 0x2f010000)) def closeEvent(event): global run run = False event.accept() win.closeEvent = closeEvent app.processEvents() try: i = 0 while run: i = i + 1 sc.handleEvents() app.processEvents() except KeyboardInterrupt: print("Bye")
def main(is_simulate): global data_q, frameData, dataOk global general_thread_stop_flag global max_timestep # gui related globals global draw_x_y, draw_z_v # thread related globals global main_stop_event # IWR1443 related Globals global CLIport, Dataport, configParameters global thm_gui_size global window global thm_model_path global my_mode warnings.simplefilter('ignore', np.RankWarning) # START QtAPPfor the plot app = QtGui.QApplication([]) # Set the plot pg.setConfigOption('background', 'w') window = pg.GraphicsWindow(title="2D scatter plot") fig_z_y = window.addPlot() fig_z_y.setXRange(-0.5, 0.5) fig_z_y.setYRange(0, 1.5) fig_z_y.setLabel('left', text='Y position (m)') fig_z_y.setLabel('bottom', text='X position (m)') draw_x_y = fig_z_y.plot([], [], pen=None, symbol='o') fig_z_v = window.addPlot() fig_z_v.setXRange(-1, 1) fig_z_v.setYRange(-1, 1) fig_z_v.setLabel('left', text='Z position (m)') fig_z_v.setLabel('bottom', text='Doppler (m/s)') draw_z_v = fig_z_v.plot([], [], pen=None, symbol='o') # create thumouse window thumouse_gui = window.addPlot() thumouse_gui.setXRange(0, thm_gui_size[0]) thumouse_gui.setYRange(0, thm_gui_size[1]) draw_thumouse_gui = thumouse_gui.plot([], [], pen=None, symbol='o') print("Started, input anything in this console and hit enter to stop") # start the prediction thread model_dict = { 'thm': load_model(thm_model_path, encoder=thm_scaler_path), 'idp': load_model(idp_model_path, encoder=onehot_decoder()) } thread1 = PredictionThread(1, model_encoder_dict=model_dict, timestep=100, thumouse_gui=draw_thumouse_gui, mode=my_mode) thread2 = InputThread(2) thread1.start() thread2.start() if not is_simulate: # start IWR1443 serial connection CLIport, Dataport = serialConfig(configFileName) configParameters = parseConfigFile(configFileName) while True: dataOk, detObj = update() if dataOk: # Store the current frame into frameData frameData[time.time()] = detObj frameRow = np.asarray( [detObj['x'], detObj['y'], detObj['z'], detObj['doppler']]).transpose() data_q.append( np.expand_dims(preprocess_frame(frameRow, isCluster=False, isClipping=False), axis=0)) # expand dim for single channeled data QtGui.QApplication.processEvents() if main_stop_event.is_set(): # set the stop flag for threads general_thread_stop_flag = True # populate data queue with dummy data so that the prediction thread can stop (data_q.append(np.zeros(data_shape)) for _ in range(max_timestep)) if not is_simulate: # close serial interface CLIport.write(('sensorStop\n').encode()) CLIport.close() Dataport.close() # wait for other threads to finish thread1.join() thread2.join() break # Stop sequence print('Stopped')
def _visualize(self): import pyqtgraph as pg import numpy as np # Enable antialiasing for prettier plots pg.setConfigOptions(antialias=True) w = pg.GraphicsWindow() w.setWindowTitle('Visualization of the Network') v = w.addViewBox() v.setAspectLocked() g = pg.GraphItem() v.addItem(g) positions = [] symbols = [] symbol_brushes = [] x = 0 y = 0 x += 1 for neuron in self.sensory_neurons: y += 1 neuron.position = (x, y) positions.append(neuron.position) symbols.append('t') symbol_brushes.append((250, 194, 5)) neuron.index = len(positions) - 1 x += len(self.sensory_neurons) y = (len(self.sensory_neurons) - len(self.interneurons)) / 2 for neuron in self.interneurons: y += 1 neuron.position = (random.uniform( x - len(self.sensory_neurons) / 1.5, x + len(self.sensory_neurons) / 1.5), y) positions.append(neuron.position) symbols.append('h') symbol_brushes.append((195, 46, 212)) neuron.index = len(positions) - 1 x += len(self.sensory_neurons) y = (len(self.sensory_neurons) - len(self.motor_neurons)) / 2 for neuron in self.motor_neurons: y += 1 neuron.position = (x, y) positions.append(neuron.position) symbols.append('s') symbol_brushes.append((19, 234, 201)) neuron.index = len(positions) - 1 while True: connections = [] lines = [] for neuron2 in self.neurons: for neuron1, weight in neuron2.subscriptions.items(): connections.append((neuron1.index, neuron2.index)) lines.append( (55, 55, 55, ((weight + 1) / 2) * 255, (weight + 1))) positions = np.asarray(positions) connections = np.asarray(connections) lines = np.asarray(lines, dtype=[('red', np.ubyte), ('green', np.ubyte), ('blue', np.ubyte), ('alpha', np.ubyte), ('width', float)]) g.setData(pos=positions, adj=connections, pen=lines, size=0.1, symbolBrush=symbol_brushes, symbol=symbols, pxMode=False) # Update the graph pg.QtGui.QApplication.processEvents() if self.thread_kill_signal: break time.sleep(0.0333)
path = "//192.168.13.10/Public/experimental data/touhoku_patch/20181018_cortex/" path_h = path + "voltage/voltage" + index + ".csv" path_i = path + "current/current" + index + ".csv" fsize = 24 sample = 20000 fig = plt.figure(figsize=(30, 14)) dfv = pd.read_csv(path_h, delimiter=',') dfc = pd.read_csv(path_i, delimiter=',') dfv.fillna(0) dfc.fillna(0) pg.setConfigOption('background', (255, 255, 255)) pg.setConfigOption('foreground', (0, 0, 0)) glaph_tab = pg.GraphicsWindow(title="single autaptic neuron") p1 = glaph_tab.addPlot(title="Vx1") p1.showGrid(True, True, 0.2) curve1 = p1.plot(dfv['index'] / sample, dfv['voltage(mV)'], pen=(0, 0, 0)) ax1 = fig.add_subplot(1, 1, 1) ax1.plot(dfv['index'] / sample, dfv['voltage(mV)'], color="black", markevery=[0, -1], zorder=1) ax1.tick_params(labelsize=fsize) ax1.set_xlabel("time[s]", fontsize=fsize) ax1.set_ylabel("membrane potential[mV]", fontsize=fsize) """ ax2 = ax1.twinx()
from pyqtgraph.Qt import QtGui, QtCore import numpy as np import pyqtgraph as pg """ Initialise window here """ app = QtGui.QApplication([]) win = pg.GraphicsWindow("Gui for training") pg.setConfigOptions(antialias=True) """ Add plot details """ p1 = win.addPlot(title="Plots") p2 = win.addPlot(title="Zoom on the selected regions") win.showMaximized() """ Add the data curves """ nPlots = 100 nSamples = 500 curves_left = [] curves_right = [] for i in range(nPlots): c1 = pg.PlotCurveItem(pen=(i, nPlots * 1.3)) c2 = pg.PlotCurveItem(pen=(i, nPlots * 1.3)) p1.addItem(c1) p2.addItem(c2) c1.setPos(0, i * 6) c2.setPos(0, i * 6) curves_left.append(c1) curves_right.append(c2)
vna.write_pll(vna.source) vna.write_pll(vna.lo) vna.write_pll(vna.source) vna.write_pll(vna.lo) vna.read_iq() vna.read_iq() return vna vna = init_vna() iqs = {'rx1': [], 'rx2': [], 'a': [], 'b': [], 'none': [], 'unknown': []} app = QtGui.QApplication([]) win = pg.GraphicsWindow(title="RX channels") #win.resize(1000,600) win.setWindowTitle('RX channels') # Enable antialiasing for prettier plots pg.setConfigOptions(antialias=True) plot = win.addPlot(title="S-parameters", labels={ 'left': 'Magnitude [dB]', 'bottom': 'Samples' }) curve1 = plot.plot(pen='y', name='S11') curve2 = plot.plot(pen='g', name='S12') plot.addLegend() plot.legend.addItem(curve1, "S11")
def __init__(self, consumer): self.win = pg.GraphicsWindow() self.win.setWindowTitle("pyQTGRAPH: Tryout") self._listeners = [] self._consumer = consumer self._currow = 0
#rom PySide.QtCore import QTime from pyqtgraph.Qt import QtGui, QtCore import numpy as np import pyqtgraph as pg import sys import struct from pylab import * import time #QtGui.QApplication.setGraphicsSystem('raster') #app = QtGui.QApplication([]) #mw = QtGui.QMainWindow() #mw.resize(800,800) win = pg.GraphicsWindow(title="Basic plotting examples") win.resize(1200, 800) #f = open('binaryFoo','rb') ################################MOCK REAL TIME DATA########################### #init data variables bufferSize = 1000 fs = float(128) data = np.zeros(bufferSize) data2 = np.zeros(bufferSize) data3 = np.zeros(bufferSize) data4 = np.zeros(bufferSize) data5 = np.zeros(bufferSize) data6 = np.zeros(bufferSize) data7 = np.zeros(bufferSize)
import serial from pyqtgraph.Qt import QtGui, QtCore import numpy as np import pyqtgraph as pg from collections import deque from tinyos.message import * from tinyos.message.Message import * from tinyos.message.SerialPacket import * from tinyos.packet.Serial import Serial import InclinometerDemo from Constants import Constants app = QtGui.QApplication([]) win = pg.GraphicsWindow(title="QuickViz") win.resize(1000, 600) win.setWindowTitle('QuickViz Accelerometer') BUF_SIZE = 500 px = win.addPlot(title="Axis X") xcurve = px.plot(pen='y') xdata = deque(np.zeros(BUF_SIZE), maxlen=BUF_SIZE) tstamp = deque(np.arange(BUF_SIZE), maxlen=BUF_SIZE) px.enableAutoRange( 'y', False) ## stop auto-scaling after the first data set is plotted
## Create image to display arr = np.ones((100, 100), dtype=float) arr[45:55, 45:55] = 0 arr[25, :] = 5 arr[:, 25] = 5 arr[75, :] = 5 arr[:, 75] = 5 arr[50, :] = 10 arr[:, 50] = 10 arr += np.sin(np.linspace(0, 20, 100)).reshape(1, 100) arr += np.random.normal(size=(100, 100)) ## create GUI app = QtWidgets.QApplication([]) w = pg.GraphicsWindow(size=(1000, 800), border=True) w.setWindowTitle('pyqtgraph example: ROI Examples') text = """Data Selection From Image.<br>\n Drag an ROI or its handles to update the selected image.<br> Hold CTRL while dragging to snap to pixel boundaries<br> and 15-degree rotation angles. """ w1 = w.addLayout(row=0, col=0) label1 = w1.addLabel(text, row=0, col=0) v1a = w1.addViewBox(row=1, col=0, lockAspect=True) v1b = w1.addViewBox(row=2, col=0, lockAspect=True) img1a = pg.ImageItem(arr) v1a.addItem(img1a) img1b = pg.ImageItem() v1b.addItem(img1b)
filtorder = 9 if patch.hasitem('arguments', 'bandpass'): freqrange = patch.getfloat('arguments', 'bandpass', multiple=True) elif patch.hasitem('arguments', 'lowpass'): freqrange = patch.getfloat('arguments', 'lowpass') freqrange = [np.nan, freqrange] elif patch.hasitem('arguments', 'highpass'): freqrange = patch.getfloat('arguments', 'highpass') freqrange = [freqrange, np.nan] else: freqrange = [np.nan, np.nan] # initialize graphical window app = QtGui.QApplication([]) win = pg.GraphicsWindow(title="EEGsynth plotsignal") win.setWindowTitle('EEGsynth plotsignal') win.setGeometry(winx, winy, winwidth, winheight) # Enable antialiasing for prettier plots pg.setConfigOptions(antialias=True) # Initialize variables timeplot = [] curve = [] curvemax = [] # Create panels for each channel for ichan in range(chan_nrs): channr = int(chanarray[ichan]) + 1
def initUI(self): # Define elements numeLbl = QtGui.QLabel('Nume') senzorLbl = QtGui.QLabel('Alege Senzor') repetariLbl = QtGui.QLabel('Nr Repetari') validRepetari = QtGui.QIntValidator(1, 500) validDurata = QtGui.QIntValidator(1, 99) validSensibil = QtGui.QIntValidator(1, 999) self.labelComBox = QtGui.QLabel('Model') self.labelSensibilitate = QtGui.QLabel('Alege sensibilitate') self.labelNrTrepte = QtGui.QLabel('Numar trepte') self.labelTreapta1 = QtGui.QLabel('Treapta 1') self.labelTipModel1 = QtGui.QLabel('Alege Model') self.labelDurataModel1 = QtGui.QLabel('Durata Model') self.labelSensibilitateInitModel1 = QtGui.QLabel( 'Sensibilitate Initiala') self.labelTreapta2 = QtGui.QLabel('Treapta 2') self.labelTipModel2 = QtGui.QLabel('Alege Model') self.labelDurataModel2 = QtGui.QLabel('Durata Model') self.labelSensibilitateInitModel2 = QtGui.QLabel( 'Sensibilitate Initiala') self.labelTreapta3 = QtGui.QLabel('Treapta 3') self.labelTipModel3 = QtGui.QLabel('Alege Model') self.labelDurataModel3 = QtGui.QLabel('Durata Model') self.labelSensibilitateInitModel3 = QtGui.QLabel( 'Sensibilitate Initiala') self.labelTreapta4 = QtGui.QLabel('Treapta 4') self.labelTipModel4 = QtGui.QLabel('Alege Model') self.labelDurataModel4 = QtGui.QLabel('Durata Model') self.labelSensibilitateInitModel4 = QtGui.QLabel( 'Sensibilitate Initiala') self.numeLineEdit = QtGui.QLineEdit() self.senzorComBox = QtGui.QComboBox() self.senzorComBox.addItems(['Senzor Superior', 'Senzor Lateral']) self.repetariInputDialog = QtGui.QLineEdit() self.repetariInputDialog.setValidator(validRepetari) self.startBtn = QtGui.QPushButton('Start') self.stopBtn = QtGui.QPushButton('Stop') self.sensibilComBox = QtGui.QComboBox() self.sensibilComBox.addItems( ['50', '100', '150', '300', '600', '1000']) self.modelComBox = QtGui.QComboBox() self.modelComBox.addItems(['Alege', 'Da', 'Nu']) self.nrTrepteComBox = QtGui.QComboBox() self.nrTrepteComBox.addItems(['1', '2', '3', '4']) # self.model1ComBox = QtGui.QComboBox() # self.model1ComBox.addItems(['Alege','Platou']) self.durataModel1InputDialog = QtGui.QLineEdit() self.durataModel1InputDialog.setValidator(validDurata) self.sensibilitInitModel1 = QtGui.QLineEdit() self.sensibilitInitModel1.setValidator(validSensibil) # self.model2ComBox = QtGui.QComboBox() # self.model2ComBox.addItems(['Alege','Platou']) self.durataModel2InputDialog = QtGui.QLineEdit() self.durataModel2InputDialog.setValidator(validDurata) self.sensibilitInitModel2 = QtGui.QLineEdit() self.sensibilitInitModel2.setValidator(validSensibil) # self.model3ComBox = QtGui.QComboBox() # self.model3ComBox.addItems(['Alege','Platou']) self.durataModel3InputDialog = QtGui.QLineEdit() self.durataModel3InputDialog.setValidator(validDurata) self.sensibilitInitModel3 = QtGui.QLineEdit() self.sensibilitInitModel3.setValidator(validSensibil) self.model4ComBox = QtGui.QComboBox() self.model4ComBox.addItems(['Alege', 'Platou']) self.durataModel4InputDialog = QtGui.QLineEdit() self.durataModel4InputDialog.setValidator(validDurata) self.sensibilitInitModel4 = QtGui.QLineEdit() self.sensibilitInitModel4.setValidator(validSensibil) self.plotGW = pg.GraphicsWindow(title="FinCon") self.repLbl = QtGui.QLabel('') self.turaLbl = QtGui.QLabel('') pg.setConfigOptions(antialias=True) # Define Layout self.grid = QtGui.QGridLayout() self.grid.setSpacing(10) self.grid.addWidget(numeLbl, 1, 0) self.grid.addWidget(self.numeLineEdit, 1, 1) self.grid.addWidget(senzorLbl, 2, 0) self.grid.addWidget(self.senzorComBox, 2, 1) self.grid.addWidget(repetariLbl, 3, 0) self.grid.addWidget(self.repetariInputDialog, 3, 1) self.grid.addWidget(self.labelComBox, 4, 0) self.grid.addWidget(self.modelComBox, 4, 1) self.grid.addWidget(self.plotGW, 2, 2, 25, 3) self.grid.addWidget(self.startBtn, 26, 0) self.grid.addWidget(self.stopBtn, 26, 1) self.grid.addWidget(self.repLbl, 1, 2) self.grid.addWidget(self.turaLbl, 1, 3) self.modelComBox.currentIndexChanged.connect(self.afisarModel) self.setLayout(self.grid) self.showMaximized() width = self.startBtn.width() self.stopBtn.setMaximumWidth(int(width)) self.startBtn.setMaximumWidth(int(width)) self.senzorComBox.setMaximumWidth(150) self.repetariInputDialog.setMaximumWidth(20) self.sensibilComBox.setMaximumWidth(150) self.modelComBox.setMaximumWidth(150) self.numeLineEdit.setMaximumWidth(150) self.durataModel1InputDialog.setMaximumWidth(20) self.durataModel2InputDialog.setMaximumWidth(20) self.durataModel3InputDialog.setMaximumWidth(20) self.durataModel4InputDialog.setMaximumWidth(20) self.sensibilitInitModel1.setMaximumWidth(50) self.sensibilitInitModel2.setMaximumWidth(50) self.sensibilitInitModel3.setMaximumWidth(50) self.sensibilitInitModel4.setMaximumWidth(50) self.setWindowTitle('FinCon 2.4') self.show()
for i in range(len(device_names)): print('<' + str(i) + '> ' + device_names[i] + '\n') dev_index = input("<Select> streaming device from the list.>>") device_name = device_names[int(dev_index)] daq_model_type = devices_name_to_model_dict[device_name] daq = daq_model_type(device_name) # add changes to default streaming device config here: if daq.device_name == 'Dev1': daq.ai_terminal_config = 'RSE' #for key, value in daq.__dict__.items(): # print(key, '=', value) app = pg.QtGui.QApplication(sys.argv) win = pg.GraphicsWindow(title=daq.device_name) plot_item1 = win.addPlot(title="Input frame (s)") plot_data_item_A = plot_item1.plot(pen=1) plot_data_item_B = plot_item1.plot(pen=2) win.nextRow() plot_item2 = win.addPlot(title="Monitor window (pts)") monitor_plot_data_item_A = plot_item2.plot(pen=1) monitor_plot_data_item_B = plot_item2.plot(pen=2) plot_timer_frame = QtCore.QTimer() plot_timer_frame.timeout.connect(update_time_plot) daq.monitor_ready_signal.connect(update_monitor_plot) daq.start_continuous_acq_n_gen() plot_timer_frame.start(100) app.exec_()
def __init__(self): # pyqtgraph stuff pg.setConfigOptions(antialias=True) self.traces = dict() self.app = QtGui.QApplication(sys.argv) self.win = pg.GraphicsWindow(title='Spectrum Analyzer') self.win.setWindowTitle('Spectrum Analyzer') self.win.setGeometry(5, 115, 1910, 1070) wf_xlabels = [(0, '0'), (2048, '2048'), (4096, '4096')] wf_xaxis = pg.AxisItem(orientation='bottom') wf_xaxis.setTicks([wf_xlabels]) wf_ylabels = [(0, '0'), (127, '128'), (255, '255')] wf_yaxis = pg.AxisItem(orientation='left') wf_yaxis.setTicks([wf_ylabels]) self.isLogAxis = False self.waveMultiplier = 4 self.isFFT = False if self.isFFT: if self.isLogAxis: sp_xlabels = [ (np.log10(10), '10'), (np.log10(100), '100'), (np.log10(1000), '1000'), (np.log10(22050), '22050') ] else: sp_xlabels = [ (10, '10'), (1000, '1000'), (10000, '10000'), (20000, '20000') ] else: sp_xlabels = [ (10, '10'), (1000, '1000'), (10000, '10000'), (15000, '15000') ] sp_xaxis = pg.AxisItem(orientation='bottom') sp_xaxis.setTicks([sp_xlabels]) self.waveform = self.win.addPlot( title='WAVEFORM', row=1, col=1, axisItems={'bottom': wf_xaxis, 'left': wf_yaxis}, ) if self.isFFT: self.spectrum = self.win.addPlot( title='SPECTRUM', row=2, col=1, axisItems={'bottom': sp_xaxis}, ) else: self.spectrum = self.win.addPlot( title='Continous wavelet function result', row=2, col=1, axisItems={'bottom': sp_xaxis}, ) # pyaudio stuff self.FORMAT = pyaudio.paInt16 self.CHANNELS = 1 self.RATE = 44100 self.CHUNK = 1024 * 2 self.p = pyaudio.PyAudio() self.stream = self.p.open( format=self.FORMAT, channels=self.CHANNELS, rate=self.RATE, input=True, output=True, frames_per_buffer=self.CHUNK, ) # waveform and spectrum x points self.x = np.arange(0, 2 * self.CHUNK, 2) self.f = np.linspace(0, self.RATE / 2, self.CHUNK / 2)
def plot(self): pg.setConfigOption('background', 'w') pg.setConfigOption('foreground', 'k') self.win = pg.GraphicsWindow() self.win.setWindowTitle('信号图') self.label = pg.LabelItem(justify='right') self.win.addItem(self.label) self.p1 = self.win.addPlot(row=1, col=0, title='Y-X') self.p2 = self.win.addPlot(row=2, col=0, title='dY/dX-X') self.p1.setMouseEnabled(x=True, y=True) self.p2.setMouseEnabled(x=True, y=True) self.p1.setMenuEnabled(enableMenu=False, enableViewBoxMenu='same') self.p1.setMenuEnabled(enableMenu=False, enableViewBoxMenu='same') self.p1.setXLink(self.p2) #self.label1 = pg.LabelItem(justify='left') #self.label1.setText( # "<span style='font-size: 18pt'>ftydurtdr</span>") #self.p1.addItem(self.label1) self.p1.setAutoVisible(y=True) self.getindex() detal_s = (self.s[1:np.size(self.s)] - self.s[0:(np.size(self.s) - 1)] ) / (self.a[1:np.size(self.a)] - self.a[0:(np.size(self.a) - 1)]) self.s1 = np.insert(detal_s, 0, self.s[0]) #detal_a = self.a[1:np.size(self.a) - 1] #self.a1=np.insert(detal_a,0,self.a[0]) self.p1.plot(self.a, self.s, pen="g") self.p2.plot(self.a, self.s1, pen="b") self.p2.setLabel("bottom", "深度(m)") self.p1.setLabel("left", self.label_left1) self.p2.setLabel("left", self.label_left2) #self.vLine = pg.InfiniteLine(angle=90, movable=True) self.vLine1 = pg.InfiniteLine(angle=90, movable=True) self.hLine = pg.InfiniteLine(angle=0, movable=False) self.vLine1.setPen('k', style=Qt.DashDotDotLine) self.hLine1 = pg.InfiniteLine(angle=0, movable=False) self.vLine = pg.InfiniteLine(angle=90, movable=True) self.vLine.setPen('k', style=Qt.DashDotDotLine) self.hLine.setPen('k', style=Qt.DashDotDotLine) self.hLine1.setPen('k', style=Qt.DashDotDotLine) self.x = self.a[0] self.lable_y = self.s[0] self.lable_diffy = self.s1[0] self.p1.addItem(self.hLine1) self.p1.addItem(self.vLine1) self.p2.addItem(self.vLine) self.p2.addItem(self.hLine) self.plot_data_start = self.p1.plot() self.plot_data1_start = self.p2.plot() self.plot_data_end = self.p1.plot() self.plot_data1_end = self.p2.plot() self.data_start_x = list() self.data_start_y = list() self.data_start_diffy = list() self.data_end_x = list() self.data_end_y = list() self.data_end_diffy = list() self.count_start = list() self.count_end = list() #self.vb = self.p1.vb #self.proxy1 = pg.SignalProxy(self.p1.scene().sigMouseMoved , rateLimit=60, slot=self.mouseMoved) #self.proxy2 = pg.SignalProxy(self.p2.scene().sigMouseMoved, rateLimit=60, slot=self.mouseMoved) #self.proxy = pg.SignalProxy(self.p2.scene().sigMouseMoved, rateLimit=60, slot=self.mouseMoved) #self.p1.scene().sigMouseMoved.connect(self.mouseMoved) #self.proxy3 = pg.SignalProxy(self.vLine.scene().sigPositionChangeFinished, rateLimit=60, slot=self.statusChange) self.vLine.sigPositionChangeFinished.connect(self.labelChange) self.vLine1.sigPositionChangeFinished.connect(self.labelChange1) #self.win.show() self.ex = pyqtgraph.exporters.ImageExporter(self.win.scene()) self.ex.parameters()['width'] = 2000
import numpy as np import pyqtgraph as pg # build lookup table lut = np.zeros((255, 3), dtype=np.ubyte) lut[:128, 0] = np.arange(0, 255, 2) lut[128:, 0] = 255 lut[:, 1] = np.arange(255) # random image data img = np.random.normal(size=(100, 100)) # GUI win = pg.GraphicsWindow() view = win.addViewBox() view.setAspectLocked(True) item = pg.ImageItem(img) item.setLookupTable(lut) item.setLevels([0, 1]) view.addItem(item) # Equivalently, you could use a ColorMap to generate the lookup table: # pos = np.array([0.0, 0.5, 1.0]) # color = np.array([[0,0,0,255], [255,128,0,255], [255,255,0,255]], dtype=np.ubyte) # map = pg.ColorMap(pos, color) # lut = map.getLookupTable(0.0, 1.0, 256) ## Start Qt event loop unless running in interactive mode. if __name__ == '__main__':
# ------------------------- MAIN ----------------------------------------- # Configurate the serial port CLIport, Dataport = serialConfig(configFileName) # Get the configuration parameters from the configuration file configParameters = parseConfigFile(configFileName) # START QtAPPfor the plot app = QtGui.QApplication([]) # Set the plot pg.setConfigOption('background', 'w') win = pg.GraphicsWindow(title="2D scatter plot") p = win.addPlot() p.setXRange(-0.5, 0.5) p.setYRange(0, 1.5) p.setLabel('left', text='Y position (m)') p.setLabel('bottom', text='X position (m)') s = p.plot([], [], pen=None, symbol='o') # Main loop targetObj = {} frameData = {} currentIndex = 0 while True: try: # Update the data and check if the data is okay dataOk = update()