我们从Python开源项目中,提取了以下18个代码示例,用于说明如何使用pyqtgraph.TextItem()。
def __init__(self,parent): """Constructor""" self.__view = parent super(Crosshair, self).__init__() self.__vLine = pg.InfiniteLine(angle=90, movable=False) self.__hLine = pg.InfiniteLine(angle=0, movable=False) self.__textPrice = pg.TextItem('price') self.__textDate = pg.TextItem('date') #mid ?y?????????????????? self.__textLastPrice = pg.TextItem('lastTickPrice') view = self.__view view.addItem(self.__textDate, ignoreBounds=True) view.addItem(self.__textPrice, ignoreBounds=True) view.addItem(self.__vLine, ignoreBounds=True) view.addItem(self.__hLine, ignoreBounds=True) view.addItem(self.__textLastPrice, ignoreBounds=True) self.proxy = pg.SignalProxy(view.scene().sigMouseMoved, rateLimit=60, slot=self.__mouseMoved) #----------------------------------------------------------------------
def newset(self): if(not self.running):return frq = self.I.set_sine1(self.frq) time.sleep(0.1) tg=int(1e6/frq/1000)+1 self.I.capture_traces(2,self.samples,tg,trigger=True) self.loop=self.delayedTask(self.samples*self.I.timebase*1e-3+10,self.plotData,frq) self.plot1.setLimits(xMin = 0,xMax = self.samples*self.I.timebase*1e-6) self.frq+=self.DELTAFRQ pos = 100*(1.*(self.frq-self.STARTFRQ)/(self.ENDFRQ-self.STARTFRQ)) self.progress.setValue(pos) if(self.frq>self.ENDFRQ and self.DELTAFRQ>0) or (self.frq<self.ENDFRQ and self.DELTAFRQ<0): print ('og',self.frq,self.ENDFRQ,self.DELTAFRQ) self.running=False #txt='<div style="text-align: center"><span style="color: #FFF;font-size:8pt;">%d-%d</span></div>'%(self.STARTFRQ,self.ENDFRQ) #text = pg.TextItem(html=txt, anchor=(0,0), border='w', fill=(0, 0, 255, 100)) #self.plot2.addItem(text) #text.setPos(self.X[-1],self.Y[-1]) #self.curveLabels.append(text) self.curves.append(self.curveAmp) self.I.set_w1(0.2)
def newset(self): if(not self.running):return frq = self.I.set_sine1(self.frq) time.sleep(0.01) tg=int(1e6/frq/500)+1 self.I.capture_traces(2,self.samples,tg,'MIC',trigger=True) self.loop=self.delayedTask(self.samples*self.I.timebase*1e-3+10,self.plotData,frq) self.plot1.setLimits(xMin = 0,xMax = self.samples*self.I.timebase*1e-6) self.frq+=self.DELTAFRQ pos = 100*(1.*(self.frq-self.STARTFRQ)/(self.ENDFRQ-self.STARTFRQ)) self.progress.setValue(pos) if(self.frq>self.ENDFRQ and self.DELTAFRQ>0) or (self.frq<self.ENDFRQ and self.DELTAFRQ<0): print ('og',self.frq,self.ENDFRQ,self.DELTAFRQ) self.running=False #txt='<div style="text-align: center"><span style="color: #FFF;font-size:8pt;">%d-%d</span></div>'%(self.STARTFRQ,self.ENDFRQ) #text = pg.TextItem(html=txt, anchor=(0,0), border='w', fill=(0, 0, 255, 100)) #self.plot2.addItem(text) #text.setPos(self.X[-1],self.Y[-1]) #self.curveLabels.append(text) self.curves.append(self.curveAmp) self.I.set_w1(0.2)
def acquire(self): V=self.I.set_pv1(self.V) VC = self.I.get_voltage('CH1',samples=20) self.X.append(VC) self.Y.append((V-VC)/1.e3) # list( ( np.linspace(V,V+self.stepV.value(),1000)-VC)/1.e3) self.curves[-1].setData(self.X,self.Y) self.V+=self.stepV.value() if self.V>self.stopV.value(): self.looptimer.stop() txt='<div style="text-align: center"><span style="color: #FFF;font-size:8pt;"># %d</span></div>'%(self.plotnum) text = pg.TextItem(html=txt, anchor=(0,0), border='w', fill=(0, 0, 255, 100)) self.plot.addItem(text) text.setPos(self.X[-1],self.Y[-1]) self.curveLabels.append(text) self.tracesBox.addItem('#%d'%(self.plotnum))
def acquire(self): V=self.I.set_pv1(self.V) VC = self.I.get_average_voltage('CH3',samples=20) self.X.append(VC) self.Y.append((V-VC)/1.e3) # list( ( np.linspace(V,V+self.stepV.value(),1000)-VC)/1.e3) self.curves[-1].setData(self.X,self.Y) self.V+=self.stepV.value() if self.V>self.stopV.value(): self.looptimer.stop() txt='<div style="text-align: center"><span style="color: #FFF;font-size:8pt;"># %d</span></div>'%(self.plotnum) text = pg.TextItem(html=txt, anchor=(0,0), border='w', fill=(0, 0, 255, 100)) self.plot.addItem(text) text.setPos(self.X[-1],self.Y[-1]) self.curveLabels.append(text) self.tracesBox.addItem('#%d'%(self.plotnum))
def acquire(self): V=self.I.set_pv2(self.V) VB = self.I.get_average_voltage('CH3',samples=10) self.X.append((V-VB)/self.RB) # list( ( np.linspace(V,V+self.stepV.value(),1000)-VC)/1.e3) VC = self.I.get_voltage('CH1',samples=10) self.Y.append((self.vcc-VC)/self.RC) # list( ( np.linspace(V,V+self.stepV.value(),1000)-VC)/1.e3) self.curves[-1].setData(self.X,self.Y) self.V+=self.STEP if self.V>self.stopV.value(): self.looptimer.stop() txt='<div style="text-align: center"><span style="color: #FFF;font-size:8pt;">%s</span></div>'%(self.traceName) text = pg.TextItem(html=txt, anchor=(0,0), border='w', fill=(0, 0, 255, 100)) self.plot.addItem(text) text.setPos(self.X[-1],self.Y[-1]) self.curveLabels.append(text) self.tracesBox.addItem(self.traceName)
def acquire(self): VG=self.I.set_pv2(self.V) self.X.append(VG) VC = self.I.get_voltage('CH1',samples=10) self.Y.append((self.VCC-VC)/self.RESISTANCE) # list( ( np.linspace(V,V+self.stepV.value(),1000)-VC)/1.e3) self.curves[-1].setData(self.X,self.Y) self.V+=self.STEP if self.V>self.stopV.value(): self.looptimer.stop() txt='<div style="text-align: center"><span style="color: #FFF;font-size:8pt;">%s</span></div>'%(self.traceName) text = pg.TextItem(html=txt, anchor=(0,0), border='w', fill=(0, 0, 255, 100)) self.plot.addItem(text) text.setPos(self.X[-1],self.Y[-1]) self.curveLabels.append(text) self.tracesBox.addItem(self.traceName)
def acquire(self): V=self.I.set_pv2(self.V) VC = self.I.get_average_voltage('CH3',samples=10) self.X.append(VC) self.Y.append((V-VC)/self.RESISTANCE) # list( ( np.linspace(V,V+self.stepV.value(),1000)-VC)/1.e3) self.curves[-1].setData(self.X,self.Y) self.V+=self.STEP if self.V>self.stopV.value(): self.looptimer.stop() txt='<div style="text-align: center"><span style="color: #FFF;font-size:8pt;">%s</span></div>'%(self.traceName) text = pg.TextItem(html=txt, anchor=(0,0), border='w', fill=(0, 0, 255, 100)) self.plot.addItem(text) text.setPos(self.X[-1],self.Y[-1]) self.curveLabels.append(text) self.tracesBox.addItem(self.traceName)
def acquire(self): V=self.I.set_pv1(self.V) VC = self.I.get_voltage('CH1',samples=10) self.X.append(VC) self.Y.append((V-VC)/self.RESISTANCE) # list( ( np.linspace(V,V+self.stepV.value(),1000)-VC)/1.e3) self.curves[-1].setData(self.X,self.Y) self.V+=self.STEP if self.V>self.stopV.value(): self.looptimer.stop() txt='<div style="text-align: center"><span style="color: #FFF;font-size:8pt;">%s</span></div>'%(self.traceName) text = pg.TextItem(html=txt, anchor=(0,0), border='w', fill=(0, 0, 255, 100)) self.plot.addItem(text) text.setPos(self.X[-1],self.Y[-1]) self.curveLabels.append(text) self.tracesBox.addItem(self.traceName)
def add_to_viewwidget(self, viewwidget=None): if viewwidget is not None: self.viewwidget = viewwidget self.viewwidget.addItem(self) # Removing the handle from this CricleROI self.removeHandle(0) # create a new free handle for the name tag, positioned at "east" on the circle. self.my_handle = self.addRotateHandle([1, 0.5], [0.5, 0.5]) self.sigRegionChangeFinished.connect(self._redraw_label) self.label = pg.TextItem(text=self.poi.get_name(), anchor=(0, 1), color= self.color ) self.setAngle(30) self.setPos(self.position + self.get_marker_offset()) # self.viewwidget.addItem(self.label)
def __init__(self, parent=None): pyqtgraph.setConfigOption('background', 'w') #before loading widget super(ExampleApp, self).__init__(parent) self.setupUi(self) self.grECG.plotItem.showGrid(True, True, 0.7) self.btnSave.clicked.connect(self.saveFig) self.btnSite.clicked.connect(self.website) stamp="DIY ECG by Scott Harden" self.stamp = pyqtgraph.TextItem(stamp,anchor=(-.01,1),color=(150,150,150), fill=pyqtgraph.mkBrush('w')) self.ear = swhear.Ear(chunk=int(100)) # determines refresh rate # optionally you can manually set the audio input device to use like this: # self.ear = swhear.Ear(chunk=int(100), device=5) # use audio input device 5 if len(self.ear.valid_input_devices()): self.ear.stream_start() self.lblDevice.setText(self.ear.msg) self.update()
def acquire(self): if self.plotType==0: V=self.I.set_pv1(self.V) VC = self.I.get_average_voltage('CH1',samples=10) self.X.append(VC) self.Y.append((V-VC)/self.CR) # list( ( np.linspace(V,V+self.stepV.value(),1000)-VC)/1.e3) elif self.plotType==1: #set pv2, measure ch3 V=self.I.set_pv2(self.V) VC = self.I.get_average_voltage('CH3',samples=10) self.X.append(VC) self.Y.append((V-VC)/self.BR) # list( ( np.linspace(V,V+self.stepV.value(),1000)-VC)/1.e3) elif self.plotType==2: #set pv2, measure ch3 V=self.I.set_pv2(self.V) VC = self.I.get_average_voltage('CH3',samples=10) self.X.append(VC) self.Y.append((V-VC)/self.BR) # list( ( np.linspace(V,V+self.stepV.value(),1000)-VC)/1.e3) self.curves[self.plotType][-1].setData(self.X,self.Y) self.V+=self.STEP pos = 100*(1.*(self.V-self.START)/(self.STOP-self.START)) self.progress.setValue(pos) if self.V>self.stopV.value(): self.looptimer.stop() txt='<div style="text-align: center"><span style="color: #FFF;font-size:8pt;">%s</span></div>'%(self.traceName) text = pg.TextItem(html=txt, anchor=(0,0), border='w', fill=(0, 0, 255, 100)) self.plot.addItem(text) text.setPos(self.X[-1],self.Y[-1]) self.curveLabels[self.plotType].append(text) self.tracesBox.addItem(self.traceName)
def _redraw_label(self): if self.label is not None: self.viewwidget.removeItem(self.label) cos_th = np.cos(self.angle() / 180. * np.pi) sin_th = np.sin(self.angle() / 180. * np.pi) text_pos = self.position\ + [self.radius * cos_th, self.radius * sin_th] if cos_th > 0 and sin_th > 0: my_anchor = (0, 1) elif cos_th > 0 and sin_th < 0: my_anchor = (0, 0) elif cos_th < 0 and sin_th < 0: my_anchor = (1, 0) else: my_anchor = (1, 1) # Updating the position of the circleROI origin in case it has been rotated. # It is important for finish=False so that this action does not call this # _redraw_label method recursively self.setPos(self.position + self.get_marker_offset(), finish=False) my_color = self.color if self.selected: my_color = self.selectcolor self.label = pg.TextItem(text=self.poi.get_name(), anchor=my_anchor, color=my_color ) self.label.setPos(text_pos[0], text_pos[1]) self.viewwidget.addItem(self.label)
def __init__(self, data, title="", dt=None): PgDataPlot.__init__(self, data) self.time_data = [np.atleast_1d(data_set.input_data[0]) for data_set in self._data] self.spatial_data = [np.atleast_1d(data_set.input_data[1]) for data_set in self._data] self.state_data = [data_set.output_data for data_set in self._data] self._pw = pg.plot(title=time.strftime("%H:%M:%S") + ' - ' + title) self._pw.addLegend() self._pw.showGrid(x=True, y=True, alpha=0.5) max_times = [max(data) for data in self.time_data] self._endtime = max(max_times) self._longest_idx = max_times.index(self._endtime) if dt is not None: self._dt = dt spat_min = np.min([np.min(data) for data in self.spatial_data]) spat_max = np.max([np.max(data) for data in self.spatial_data]) self._pw.setXRange(spat_min, spat_max) state_min = np.min([np.min(data) for data in self.state_data]) state_max = np.max([np.max(data) for data in self.state_data]) self._pw.setYRange(state_min, state_max) self._time_text = pg.TextItem('t= 0') self._pw.addItem(self._time_text) self._time_text.setPos(.9 * spat_max, .9 * state_min) self._plot_data_items = [] for idx, data_set in enumerate(self._data): self._plot_data_items.append(pg.PlotDataItem(pen=colors[idx], name=data_set.name)) self._pw.addItem(self._plot_data_items[-1]) self._curr_frame = 0 self._t = 0 self._timer = pg.QtCore.QTimer() self._timer.timeout.connect(self._update_plot) self._timer.start(1e3 * self._dt)
def __init__(self, position, label="", setvalfn=None, confirmfn=None, color=(225, 0, 0), report=None): pg.UIGraphicsItem.__init__(self) self.moving = False self.mouseHovering = False self.report = report hp = pg.mkPen(color=color, width=3) np = pg.mkPen(color=color, width=2) self.line = pg.InfiniteLine(angle=90, movable=True, pen=np, hoverPen=hp) if position is not None: self.line.setValue(position) else: self.line.setValue(0) self.line.hide() self.line.setCursor(Qt.SizeHorCursor) self.line.setParentItem(self) self.line.sigPositionChangeFinished.connect(self.lineMoveFinished) self.line.sigPositionChanged.connect(self.lineMoved) self.label = pg.TextItem("", anchor=(0,0)) self.label.setText(label, color=color) self.label.setParentItem(self) self.setvalfn = setvalfn self.confirmfn = confirmfn self.lastTransform = None
def plotColumns(self): selected = self.tbl.selectedRanges() x=[] y=[] xname='' ; yname = '' if len(selected)==0: self.displayDialog('Please Select at least two columns') return if len(selected)==1: if selected[0].leftColumn() == selected[0].rightColumn(): self.displayDialog('Please Select at least two columns') return for a in xrange(selected[0].topRow(), selected[0].bottomRow()+1): x.append(float(self.tbl.item(a,selected[0].leftColumn()).text())) for a in xrange(selected[0].topRow(), selected[0].bottomRow()+1): y.append(float(self.tbl.item(a,selected[0].leftColumn()+1).text())) xname = str(self.tbl.horizontalHeaderItem(selected[0].leftColumn()).text()) yname = str(self.tbl.horizontalHeaderItem(selected[0].leftColumn()+1).text()) elif len(selected)==2: for a in xrange(selected[0].topRow(), selected[0].bottomRow()+1): x.append(float(self.tbl.item(a,selected[0].leftColumn()).text())) for a in xrange(selected[1].topRow(), selected[1].bottomRow()+1): y.append(float(self.tbl.item(a,selected[1].leftColumn()).text())) xname = str(self.tbl.horizontalHeaderItem(selected[0].leftColumn()).text()) yname = str(self.tbl.horizontalHeaderItem(selected[1].leftColumn()).text()) msgBox = QtGui.QMessageBox() msgBox.setText("Plotting \nxaxis : %s\nyaxis : %s"%(xname, yname)) msgBox.setStandardButtons(QtGui.QMessageBox.Cancel) noRev = msgBox.addButton(self.tr("Plot"), QtGui.QMessageBox.ActionRole) rev = msgBox.addButton(self.tr("Swap Axes and plot"), QtGui.QMessageBox.ActionRole) ret = msgBox.exec_() if msgBox.clickedButton() == rev: tmp = y; y=x;x=tmp tmp = yname; yname=xname;xname=tmp elif ret == QtGui.QMessageBox.Cancel: return AllItems = [self.plotList.itemText(i) for i in range(self.plotList.count())] num=1 self.plot.getAxis('bottom').setLabel(xname) self.plot.getAxis('left').setLabel(yname) name = xname + ' vs ' + yname while name+' #'+str(num) in AllItems: num+=1 name = name+' #'+str(num) self.eTabs.setCurrentIndex(3) #Switch to plot tab curve = self.addCurve(self.plot,name) curve.setData(x,y) txt='<div style="text-align: center"><span style="color: #FFF;font-size:8pt;">%s</span></div>'%(name) text = pg.TextItem(html=txt, anchor=(0,0), border='w', fill=(0, 0, 255, 100)) self.plot.addItem(text) text.setPos(x[-1],y[-1]) self.plotList.addItem(name) self.curveLabels.append(text) self.curves.append(curve) self.plot.autoRange() self.plot.setXRange(min(x),max(x)*1.3) self.plot.setYRange(min(y),max(y)*1.3)
def setup(self): self.settings.New('spec_index', dtype=int, initial=0) self.settings.spec_index.add_listener(self.on_spec_index_change) self.ui = QtWidgets.QGroupBox() self.ui.setLayout(QtWidgets.QVBoxLayout()) self.ui.spec_index_doubleSpinBox = QtWidgets.QDoubleSpinBox() self.settings.spec_index.connect_bidir_to_widget(self.ui.spec_index_doubleSpinBox) self.ui.layout().addWidget(self.ui.spec_index_doubleSpinBox) self.graph_layout = pg.GraphicsLayoutWidget() self.ui.layout().addWidget(self.graph_layout) self.power_plot = self.graph_layout.addPlot() self.power_plot.setLogMode(x=True, y=True) self.power_plotcurve = self.power_plot.plot([1],[1], name='Data') self.power_fit_plotcurve = self.power_plot.plot([1],[1],pen='r', name='Fit') self.power_plot_arrow = pg.ArrowItem() self.power_plot_arrow.setPos(0,0) self.power_plot.addItem(self.power_plot_arrow) self.power_plot_lr = pg.LinearRegionItem([1,2]) self.power_plot_lr.setZValue(-10) self.power_plot.addItem(self.power_plot_lr) self.power_plot_lr.sigRegionChanged.connect(self.redo_fit) #self.power_plot_legend = pg.LegendItem() #self.power_plot.addItem(self.power_plot_legend) #self.power_plot_legend.addItem(self.power_plotcurve) #self.power_plot_legend.addItem(self.power_fit_plotcurve) self.fit_text = pg.TextItem("fit") self.fit_text.setParentItem(self.power_plot_lr, ) self.graph_layout.nextRow() self.spec_plot = self.graph_layout.addPlot() self.spec_plotcurve = self.spec_plot.plot([0])