我们从Python开源项目中,提取了以下23个代码示例,用于说明如何使用pyqtgraph.InfiniteLine()。
def test_getViewWidget_deleted(): view = pg.PlotWidget() item = pg.InfiniteLine() view.addItem(item) assert item.getViewWidget() is view # Arrange to have Qt automatically delete the view widget obj = pg.QtGui.QWidget() view.setParent(obj) del obj gc.collect() assert not pg.Qt.isQObjectAlive(view) assert item.getViewWidget() is None #if __name__ == '__main__': #view = pg.PlotItem() #vref = weakref.ref(view) #item = pg.InfiniteLine() #view.addItem(item) #del view #gc.collect()
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 enableCrossHairs(self,plot,curves=[]): """ Enables crosshairs on the specified plot .. tabularcolumns:: |p{3cm}|p{11cm}| =============== ============================================================================================ **Arguments** =============== ============================================================================================ plot The plot to activate this feature on =============== ============================================================================================ """ plot.setTitle('') vLine = pg.InfiniteLine(angle=90, movable=False,pen=[100,100,200,200]) plot.addItem(vLine, ignoreBounds=True) hLine = pg.InfiniteLine(angle=0, movable=False,pen=[100,100,200,200]) plot.addItem(hLine, ignoreBounds=True) plot.hLine = hLine; plot.vLine = vLine crossHairPartial = functools.partial(self.crossHairEvent,plot) proxy = pg.SignalProxy(plot.scene().sigMouseClicked, rateLimit=60, slot=crossHairPartial) plot.proxy = proxy plot.mousePoint=None
def plot_liss(self): lissx = self.Liss_x.currentText() lissy = self.Liss_y.currentText() self.liss_x = self.Liss_x.currentIndex() self.liss_y = self.Liss_y.currentIndex() if not (self.channel_states[self.liss_x] and self.channel_states[self.liss_y]): QtGui.QMessageBox.about(self, 'Error : Insufficient Data', 'Please enable the selected channels in the oscilloscope') return self.liss_win = pg.GraphicsWindow(title="Basic plotting examples") self.liss_win.setWindowTitle('pyqtgraph example: Plotting') self.p1 = self.liss_win.addPlot(title="Lissajous: x : %s vs y : %s"%(lissx,lissy),x=self.I.achans[self.liss_x].get_yaxis(),y=self.I.achans[self.liss_y].get_yaxis()) self.p1.setLabel('left',lissy);self.p1.setLabel('bottom',lissx) self.p1.getAxis('left').setGrid(170) self.p1.getAxis('bottom').setGrid(170) self.lissvLine = pg.InfiniteLine(angle=90, movable=False,pen=[100,100,200,200]) self.p1.addItem(self.lissvLine, ignoreBounds=True) self.lisshLine = pg.InfiniteLine(angle=0, movable=False,pen=[100,100,200,200]) self.p1.addItem(self.lisshLine, ignoreBounds=True) self.vb = self.p1.vb self.lissproxy = pg.SignalProxy(self.p1.scene().sigMouseClicked, rateLimit=60, slot=self.lissMouseClicked)
def analysis_settings_changed(self): """ @return: """ # Check if the signal has been emitted by a dragged line in the laser plot if self.sender().__class__.__name__ == 'InfiniteLine': signal_start = self.sig_start_line.value() signal_end = self.sig_end_line.value() norm_start = self.ref_start_line.value() norm_end = self.ref_end_line.value() else: signal_width = self._pe.extract_param_ana_window_width_DSpinBox.value() signal_start = self._pe.extract_param_ana_window_start_DSpinBox.value() signal_end = signal_start + signal_width norm_width = self._pe.extract_param_ref_window_width_DSpinBox.value() norm_start = self._pe.extract_param_ref_window_start_DSpinBox.value() norm_end = norm_start + norm_width method = self._pe.extract_param_analysis_method_comboBox.currentText() self._pulsed_master_logic.analysis_settings_changed(method, signal_start, signal_end, norm_start, norm_end) return
def __init__(self): pg.HistogramLUTWidget.__init__(self, image=None) self.plots = [] self.axis.setLabel('Displacement / m') zero_marker = pg.InfiniteLine( pos=0, angle=0, pen='w', movable=False) zero_marker.setValue(0.) zero_marker.setZValue(1000) self.vb.addItem(zero_marker) self.axis.setLabel('Displacement / m') self.setSymColormap()
def __init__(self, parent_plot): _KiteSubplotPlot.__init__(self, parent_plot) self.structure = pg.PlotDataItem(antialias=True) self.variance = pg.InfiniteLine( pen=pen_covariance, angle=0, movable=True, hoverPen=None, label='Variance: {value:.5f}', labelOpts={'position': .975, 'anchors': ((1., 0.), (1., 1.)), 'color': pg.mkColor(255, 255, 255, 155)}) self.plot.setLabels(bottom={'Distance', 'm'}, left='Covariance (m<sup>2</sup>)') self.addItem(self.structure) self.addItem(self.variance) self.model.sigCovarianceChanged.connect( self.update) self.variance.sigPositionChangeFinished.connect( self.changeVariance) self.update()
def __init__(self, plot): pg.HistogramLUTWidget.__init__(self, image=plot.image) self._plot = plot zero_marker = pg.InfiniteLine( pos=0, angle=0, pen='w', movable=False) zero_marker.setValue(0.) zero_marker.setZValue(1000) self.vb.addItem(zero_marker) self.axis.setLabel('Displacement / m') # self.plot.rotate(-90) # self.layout.rotate(90) # self.gradient.setOrientation('bottom') self.setSymColormap() self._plot.image.sigImageChanged.connect(self.imageChanged) # self.isoCurveControl()
def test_InfiniteLine(): # Test basic InfiniteLine API plt = pg.plot() plt.setXRange(-10, 10) plt.setYRange(-10, 10) plt.resize(600, 600) # seemingly arbitrary requirements; might need longer wait time for some platforms.. QtTest.QTest.qWaitForWindowShown(plt) QtTest.QTest.qWait(100) vline = plt.addLine(x=1) assert vline.angle == 90 br = vline.mapToView(QtGui.QPolygonF(vline.boundingRect())) assert br.containsPoint(pg.Point(1, 5), QtCore.Qt.OddEvenFill) assert not br.containsPoint(pg.Point(5, 0), QtCore.Qt.OddEvenFill) hline = plt.addLine(y=0) assert hline.angle == 0 assert hline.boundingRect().contains(pg.Point(5, 0)) assert not hline.boundingRect().contains(pg.Point(0, 5)) vline.setValue(2) assert vline.value() == 2 vline.setPos(pg.Point(4, -5)) assert vline.value() == 4 oline = pg.InfiniteLine(angle=30) plt.addItem(oline) oline.setPos(pg.Point(1, -1)) assert oline.angle == 30 assert oline.pos() == pg.Point(1, -1) assert oline.value() == [1, -1] # test bounding rect for oblique line br = oline.mapToScene(oline.boundingRect()) pos = oline.mapToScene(pg.Point(2, 0)) assert br.containsPoint(pos, QtCore.Qt.OddEvenFill) px = pg.Point(-0.5, -1.0 / 3**0.5) assert br.containsPoint(pos + 5 * px, QtCore.Qt.OddEvenFill) assert not br.containsPoint(pos + 7 * px, QtCore.Qt.OddEvenFill)
def test_getViewWidget(): view = pg.PlotWidget() vref = weakref.ref(view) item = pg.InfiniteLine() view.addItem(item) assert item.getViewWidget() is view del view gc.collect() assert vref() is None assert item.getViewWidget() is None
def _update_time_cursors(self): """ Update the time lines of all plot windows """ for title, dock in self.area.findAll()[1].items(): if title in self.non_plotting_docks: continue for widget in dock.widgets: for item in widget.getPlotItem().items: if isinstance(item, pg.InfiniteLine): item.setValue(self.playbackTime)
def __init__(self, **args): pg.InfiniteLine.__init__(self, **args) # self.setPen(QtGui.QPen(QtGui.QColor(255, 0, 255),0.5))
def __init__(self, *args, **kwargs): pg.InfiniteLine.__init__(self, *args, **kwargs) self.setCursor(QtCore.Qt.SizeVerCursor)
def isoCurveControl(self): iso_ctrl = pg.InfiniteLine( pos=0, angle=0, pen='g', movable=True) iso_ctrl.setValue(0.) iso_ctrl.setZValue(1000) def isolineChange(): self._plot.iso.setLevel(iso_ctrl.value()) iso_ctrl.sigDragged.connect(isolineChange) self.vb.addItem(iso_ctrl)
def getPortList(self)->list: return [self.list_w.item(i) for i in range(self.list_w.count())] # vLine = pg.InfiniteLine(angle=90, movable=False) # hLine = pg.InfiniteLine(angle=0, movable=False) # p3.addItem(vLine, ignoreBounds=True) # p3.addItem(hLine, ignoreBounds=True) # def mouseMoved(evt): # pos = p3.lastMousePos # if p3.sceneBoundingRect().contains(pos): # mousePoint = p3.getPlotItem().vb.mapSceneToView(pos) # index = int(mousePoint.x()) # # vLine.setPos(mousePoint.x()) # hLine.setPos(mousePoint.y()) # # p3.scene().sigMouseHover.connect(mouseMoved) # # def update(): # global data3, ptr3 # data3[ptr3] = np.random.normal() # ptr3 += 1 # if ptr3 >= data3.shape[0]: # tmp = data3 # data3 = np.empty(data3.shape[0] * 2) # data3[:tmp.shape[0]] = tmp # curve3.setData(data3[:ptr3]) # p3.getPlotItem().setLabel('top', "%f" % ptr3) # curve3.setPos(-ptr3, 0) # # curve4.setData(data3[:ptr3]) # # curve4.setPos(-ptr3, 0)
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 __init__(self, parent=None,**kwargs): super(AppWindow, self).__init__(parent) self.setupUi(self) self.I=kwargs.get('I',None) self.setWindowTitle(self.I.H.version_string+' : '+params.get('name','').replace('\n',' ') ) from PSL.analyticsClass import analyticsClass self.math = analyticsClass() self.prescalerValue=0 self.plot=self.add2DPlot(self.plot_area,enableMenu=True) self.enableCrossHairs(self.plot,[]) labelStyle = {'color': 'rgb(255,255,255)', 'font-size': '11pt'} self.plot.setLabel('left','V (CH1)', units='V',**labelStyle) self.plot.setLabel('bottom','Time', units='S',**labelStyle) self.hLine = pg.InfiniteLine(angle=0, movable=False,pen=[255,10,20,255]) self.plot.addItem(self.hLine, ignoreBounds=True) self.hLine.setPos(3.3) self.sh=2; self.icg=2; self.samples=3694; self.tweak = 1 self.chan = 'AN8' self.timer = self.newTimer() self.legend = self.plot.addLegend(offset=(-10,30)) self.curveCH1 = self.addCurve(self.plot,'INPUT(%s)'%self.chan) self.autoRange() self.WidgetLayout.setAlignment(QtCore.Qt.AlignLeft) self.ControlsLayout.setAlignment(QtCore.Qt.AlignRight) self.ControlsLayout.addWidget(self.setStateIcon(I=self.I)) #Utility widgets self.I.set_pv1(4) #Control widgets a1={'TITLE':'SH','MIN':2,'MAX':10,'FUNC':self.set_timebase,'UNITS':'S','TOOLTIP':'Set SH pulse width, and timebase'} self.ControlsLayout.addWidget(self.dialIcon(**a1)) self.set_timebase(2) a1={'TITLE':'Average','MIN':1,'MAX':5,'FUNC':self.set_tweak,'UNITS':' times','TOOLTIP':'Average samples before displaying'} T = self.dialIcon(**a1) T.dial.setPageStep(1) T.dial.setValue(1) self.ControlsLayout.addWidget(T) a1={'TITLE':'ICG','MIN':1,'MAX':65000,'FUNC':self.set_icg,'UNITS':'S','TOOLTIP':'Set ICG'} self.WidgetLayout.addWidget(self.dialIcon(**a1)) self.I.set_sine2(1000) self.running=True self.fit = False self.timer.singleShot(100,self.run) self.Y = np.zeros(3648) self.num = 0
def create_plot(self, item): """ Creates a plot widget based on the given item. If a plot for this item is already open no new plot is created but the existing one is raised up again. Args: item(Qt.ListItem): Item to plot. """ title = str(item.text()) if title in self.non_plotting_docks: self._logger.error("Title '{}' not allowed for a plot window since" "it would shadow on of the reserved " "names".format(title)) # check if plot has already been opened if title in self.area.findAll()[1]: self.area.docks[title].raiseDock() return # collect data data = self._get_data_by_name(title) t = self.currentDataset["results"]["time"] unit = self._get_units(title) if "." in title: name = title.split(".")[1] else: name = title # create plot widget widget = pg.PlotWidget(title=title) widget.showGrid(True, True) widget.plot(x=t, y=data) widget.getPlotItem().getAxis("bottom").setLabel(text="Time", units="s") widget.getPlotItem().getAxis("left").setLabel(text=name, units=unit) # add a time line time_line = pg.InfiniteLine(self.playbackTime, angle=90, movable=False, pen=pg.mkPen("#FF0000", width=2.0)) widget.getPlotItem().addItem(time_line) # create dock container and add it to dock area dock = pg.dockarea.Dock(title, closable=True) dock.addWidget(widget) self.area.addDock(dock, "above", self.plotDockPlaceholder)
def scan_specific_setup(self): self.settings.New('kk_start', dtype=int, initial=0) self.settings.New('kk_stop', dtype=int, initial=100) self.settings.New('bg_sub', dtype=bool, initial=True) self.settings.New('e_exp', dtype=float, initial=1.0) self.settings.New('auto_recompute', dtype=bool, initial=True) self.settings.New('spatial_blur', dtype=bool, initial=False) self.settings.New('blur_sigma', dtype=float, initial=True) self.settings.New('map_display', dtype=str, initial='tau_x', choices=('tau_x', 'total_counts')) self.settings_ui = self.settings.New_UI() self.compute_button = QtWidgets.QPushButton("Go") self.settings_ui.layout().addRow("Compute:", self.compute_button) self.compute_button.clicked.connect(self.compute_lifetime_map) #self.splitter.insertWidget(0, self.settings_ui ) self.dockarea.addDock(name='settings', widget=self.settings_ui, position='left') self.settings.kk_start.add_listener(self.on_update_kk_bounds) self.settings.kk_stop.add_listener(self.on_update_kk_bounds) for lqname in ['kk_start', 'kk_stop', 'bg_sub', 'e_exp', 'spatial_blur', 'blur_sigma', 'map_display']: self.settings.get_lq(lqname).add_listener(self.on_param_changes) # set spectral plot to be semilog-y self.spec_plot.setLogMode(False, True) self.spec_plot.setLabel('left', 'Intensity', units='counts') self.spec_plot.setLabel('bottom', 'time', units='ns') self.kk_start_vline = pg.InfiniteLine(0, angle=90, pen=1, movable=False, )#name='kk_start') self.kk_stop_vline = pg.InfiniteLine(0, angle=90, pen=1, movable=False, )#name='kk_stop') self.tau_x_vline = pg.InfiniteLine(0, angle=90, pen=1, movable=False, )#name='tau_x') self.spec_plot.addItem(self.kk_start_vline, ignoreBounds=True) self.spec_plot.addItem(self.kk_stop_vline, ignoreBounds=True) self.spec_plot.addItem(self.tau_x_vline, ignoreBounds=True) self.point_plotdata_bgsub = self.spec_plot.plot(pen='g')
def __init__(self, *args, **kwargs): super(PlotSubWindow, self).__init__(*args, **kwargs) self._plots = [] self._dynamic_axis = None self._plot_widget = None self._plot_item = None self._plots_units = None self._rois = [] self._measure_rois = [] self._centroid_roi = None self._is_selected = True self._layer_items = [] self.disable_errors = False self.disable_mask = True dispatch.setup(self) self._dynamic_axis = DynamicAxisItem(orientation='top') self._plot_widget = pg.PlotWidget( axisItems={'top': self._dynamic_axis}) # self.setCentralWidget(self._plot_widget) self.vertical_layout.insertWidget(0, self._plot_widget) self._plot_item = self._plot_widget.getPlotItem() self._plot_item.showAxis('top', True) # Add grids to the plot self._plot_item.showGrid(True, True) self._setup_connections() self.linelists = [] # Initial color list for this sub window self._available_colors = cycle(AVAILABLE_COLORS) # Incorporate event filter self.installEventFilter(self) # Create a single vertical line object that can be used to indicate # wavelength position self._disp_line = pg.InfiniteLine(movable=True, pen={'color': 'g'}) self._plot_item.addItem(self._disp_line) # When the user moves the dispersion vertical line, send an event self._disp_line.sigPositionChanged.connect(lambda: dispatch.change_dispersion_position.emit( pos=self._disp_line.value()))