def updateWin(): windowmin = spin_windowmin.value() windowmax = spin_windowmax.value() if windowmax > windowmin: plot_big = generate_datascope(raw_data, [windowmin, windowmax]) plot_zoom = generate_datascope(raw_data, [windowmin, windowmax]) plot_window_big.clear() plot_window_zoom.clear() region = pg.LinearRegionItem() region.setZValue(100) plot_big.addItem(region) def update9(): region.setZValue(100) minX, maxX = region.getRegion() plot_zoom.setXRange(minX, maxX, padding=0) def updateRegion(window, viewRange): rgn = viewRange[0] region.setRegion(rgn) region.sigRegionChanged.connect(update9) plot_zoom.sigRangeChanged.connect(updateRegion) region.setRegion([windowmin + 1, windowmin + 2]) plot_window_big.addItem(plot_big) plot_window_zoom.addItem(plot_zoom)
def __init__(self): QtGui.QWidget.__init__(self) self.pl = pg.PlotWidget() self.roi = pg.LinearRegionItem([-0.5, 0.5], bounds=[-1, 1], movable=True) self.pl.getViewBox().setBackgroundColor((0, 0, 0, 255)) x = np.cos(np.linspace(0, 2 * np.pi, 1000)) y = np.sin(np.linspace(0, 4 * np.pi, 1000)) self.energySpinBox = QtGui.QSpinBox() self.energySpinBox.setMinimum(0) self.energySpinBox.setMaximum(0) self.slider = QtGui.QSlider() self.slider.setMinimum(0) self.slider.setMaximum(0) self.slider.setOrientation(QtCore.Qt.Horizontal) self.energyLabel = QtGui.QLabel("Energy: %7.2f eV" % 0) self.slider.valueChanged.connect(self.energySpinBox.setValue) self.energySpinBox.valueChanged.connect(self.slider.setValue) self.energySpinBox.valueChanged.connect(self.setEnergyLabelText) self.layout = QtGui.QVBoxLayout() self.layoutSelection = QtGui.QHBoxLayout() self.layout.addWidget(self.pl) self.layoutSelection.addWidget(self.energySpinBox) self.layoutSelection.addWidget(self.energyLabel) self.layoutSelection.addWidget(self.slider) self.layout.addLayout(self.layoutSelection) self.layout.setSpacing(0) self.setLayout(self.layout) self.pl.plot(x, y) self.pl.addItem(self.roi) data.fileLoaded.connect(self.onFileLoad) data.updateState.connect(self.updateImage)
def __init__(self, parent=None): super(ArchiveSpanWidget, self).__init__( parent, axisItems={'bottom': TimeAxisItemArchive(orientation='bottom')}) self.pltItem = self.getPlotItem() self.pltItem.setMenuEnabled(enableMenu=False) # Turn off the auto ranging self.pltItem.vb.disableAutoRange() # Don't plot anything outside of the plot limits self.pltItem.setClipToView(True) # Only show the bottom axis self.pltItem.hideAxis('left') self.pltItem.hideButtons() # Give this widget a span select, for zooming self.span = pg.LinearRegionItem([500, 1000]) self.addItem(self.span) # Give a name to the data availability regions self.boxes = [] # Give some x-limits (do not go prior/after to 1970/2200) self.getPlotItem().setLimits(xMin=0, xMax=UTCDateTime('2200-01-01').timestamp) # No y-axis panning or zooming allowed self.pltItem.vb.setMouseEnabled(y=False) self.pltItem.setYRange(0, 1) # Give some text upon hovering, and allow events to be added on double clicking addArchiveWidgetElements(self)
def setup_region(self, name): plot = self.plots_dict[name]['plot'] self.plots_dict[name]['region'] = pg.LinearRegionItem((0, 0)) region = self.plots_dict[name]['region'] region.setMovable(False) # region.setZValue(-10) plot.addItem(region)
def __init__(self,): super(KViewer, self).__init__() self.raw_data = None self.main_layout = QVBoxLayout(self) self.setting_layout = QHBoxLayout(self) self.child_graph_layout = QVBoxLayout(self) self.region = pg.LinearRegionItem() self.region_minx = 0 # region控制框的宽度 self.region_maxx = 0 self.range_control_plt = pg.PlotWidget() self.setting_view_btn = QPushButton('显示') self.setting_add_child_btn = QPushButton('增加子图') self.setting_remove_child_btn = QPushButton('删除子图') self.setting_end_date = QDateEdit() self.setting_start_date = QDateEdit() self.setting_bar_type_cb = QComboBox() self.setting_symbol_edit = QLineEdit() # 品种 self.setting_exchange_cb = QComboBox() #self.setting_exchange_edit = QLineEdit() # 交易所 self.setting_contract_edit = QLineEdit() # 合约 self.setting_dic = {} self.setup_ui() self.setup_range_control_view() self.main_child_graph = ChildGraph(False) self.main_child_graph.main_child_plt_changed.connect(self.main_child_plt_changed) self.child_graph_list = [] second_child_graph = ChildGraph(True) self.child_graph_list.append(second_child_graph) self.child_graph_layout.addWidget(self.main_child_graph,stretch=2) self.child_graph_layout.addWidget(second_child_graph, stretch=2) self.child_graph_layout.addWidget(self.range_control_plt, stretch=1) self.main_layout.addLayout(self.setting_layout) self.main_layout.addLayout(self.child_graph_layout) self.setLayout(self.main_layout)
def init_data(self): self.Options = weakref.ref(self.Main.Options)() ### plot self.vline.setBounds((0, self.Main.Data.nFrames - 1)) for n in range(self.Main.Data.nFiles): pen = pg.mkPen(self.Data_Display.colors[n], width=2) trace = self.plotItem.plot(pen=pen) self.traces.append(trace) self.plotItem.setRange(xRange=[0, self.Main.Data.nFrames], disableAutoRange=False) self.stim_region = pg.LinearRegionItem(values=[ self.Options.preprocessing['stimulus_onset'], self.Options.preprocessing['stimulus_offset'] ], movable=False, brush=pg.mkBrush( [50, 50, 50, 100])) for line in self.stim_region.lines: line.hide() self.stim_region.setZValue(-1000) self.plotItem.addItem(self.stim_region) pass
def __init__(self, ui, channel, start=None, stop=None, status=None, got_data=None, internal=None, internal_dye=None, target_layer=None): self.ui = ui params = [ {'name': 'channel', 'type': 'list', 'values': ui.list_channels()}, {'name': 'status', 'type': 'list', 'values': ['No seal', 'Low seal', 'GOhm seal', 'Technical failure', 'No attempt', 'Not recorded']}, {'name': 'got data', 'type': 'bool'}, {'name': 'internal', 'type': 'list', 'values': [''] + constants.INTERNAL_RECIPES}, {'name': 'internal dye', 'type': 'list', 'values': [''] + constants.INTERNAL_DYES}, {'name': 'target layer', 'type': 'list', 'values': [''] + constants.LAYERS}, {'name': 'morphology', 'type': 'list', 'values': {'':'', 'pyramidal':'pyr', 'non-pyramidal':'nonpyr', 'ambiguous':'?', 'no morphology':'x'}}, ] pg.parametertree.parameterTypes.GroupParameter.__init__(self, name="Pipette?", children=params, removable=True) self.child('got data').sigValueChanged.connect(self._got_data_changed) region = [0, 1] if start is not None: region[0] = start if stop is not None: region[1] = stop self.region = pg.LinearRegionItem(region) self.region.setZValue(-10) if channel is not None: self['channel'] = channel if status is not None: self['status'] = status if got_data is not None: self['got data'] = got_data if internal is not None: self['internal'] = internal if internal_dye is not None: self['internal dye'] = internal_dye if target_layer is not None: self['target layer'] = target_layer
def add_static_plot_and_numbers(self): self.regions = [] self.portion_plots = [] self.all_data_plots = [] for no in range(self.N_CH): # Region of selection in the 'all_data_plot' self.regions.append(pg.LinearRegionItem()) # Instanciate the plot containing the crosshair self.portion_plots.append(pg.PlotWidget()) # Instanciate the plot containing all the data self.all_data_plots.append(pg.PlotWidget()) self.all_data_plots[no].setXRange(0, 2000) # Portion of the graph row = no * 2 + 1 col = 1 rowspan = 1 colspan = 2 self.tab3.layout.addWidget(self.portion_plots[no], row, col, rowspan, colspan) # All the values open from the saved file row = no * 2 + 1 col = 3 rowspan = 1 colspan = 2 self.tab3.layout.addWidget(self.all_data_plots[no], row, col, rowspan, colspan) # Create the number button self.assign_n_to_ch()
def __init__(self, eeg_plot, one_ch_deque, experiment_queue, t_queue, t_init, n_data_created, pen_color, ch, lock): self.eeg_plot = eeg_plot self.one_ch_deque = one_ch_deque self.experiment_queue = experiment_queue self.t_queue = t_queue self.t_init = t_init self.n_data_created = n_data_created[0] self.ch = ch self.lock = lock self.N_DATA = len(one_ch_deque) self.curve_eeg = self.eeg_plot.plot( self.t_queue, deque(np.zeros(self.N_DATA), maxlen=self.N_DATA)) self.curve_eeg.setPen(pen_color) # Show the position where events in experiments happen self.regions = [] red = (255, 0, 0, 40) green = (0, 255, 0, 40) blue = (0, 0, 255, 40) yellow = (255, 255, 0, 40) purple = (146, 56, 219, 40) self.region_brush = [red, green, blue, yellow, purple] self.brush = self.region_brush[1] self.exp_queue_temp = self.experiment_queue for line_no in range(6): self.regions.append(pg.LinearRegionItem()) self.eeg_plot.addItem(self.regions[line_no], ignoreBounds=True) self.regions[line_no].setRegion([0, 0])
def update_stim_regions(self): """ delete all possibly present stimulus regions and draw new ones """ # delete preset if self.stim_regions != None: for i in range(self.nStimClasses): for stim_region in self.stim_regions[i]: self.plotItems[i].removeItem(stim_region) self.stim_regions = [] # draw new ones for i, StimClass in enumerate(range(self.nStimClasses)): self.stim_regions.append([]) for stim_id in range( self.Main.Options.preprocessing['stimuli'].shape[0]): stim_frames = self.Main.Options.preprocessing['stimuli'][ stim_id] stim_region = pg.LinearRegionItem(values=stim_frames, movable=False, brush=pg.mkBrush( [50, 50, 50, 100])) for line in stim_region.lines: line.hide() stim_region.setZValue(-1000) self.plotItems[i].addItem(stim_region) self.stim_regions[i].append(stim_region)
def create_time_span_dock(self): time_span_dock = InnerDock(self.main_layout, 'Time span', b_pos=(0, 2), toggle_button=True, size=(1, 1)) self.dock_area.addDock(time_span_dock.dock) # Date d_axis = DateAxis(orientation='bottom') # time plot region t_plot = pg.PlotWidget(background=dark_grey, axisItems={'bottom': d_axis}) t_plot.setXRange(self.plot_range_left, self.plot_range_right) t_plot.hideAxis('left') # Region t_region = pg.LinearRegionItem([self.t_span_right, self.t_span_left]) t_region.sigRegionChanged.connect( partial(self.change_t_boundaries, t_region)) t_plot.addItem(t_region, ignoreBounds=True) # Add date to # dates = np.arange(2) * (3600*24*356) # t_plot.plot(x=dates, y=[0, 0], symbol='o') time_span_dock.layout.addWidget(t_plot) return time_span_dock, t_plot
def setup_graph(self): self.win = pg.GraphicsWindow() self.win.setMinimumSize(350, 350) self.graph_label = pg.LabelItem(justify='right') self.win.addItem(self.graph_label, row=1, col=1) self.p1 = self.win.addPlot(row=2, col=1) self.p2 = self.win.addPlot(row=3, col=1) self.p1.vb.setMouseEnabled(x=False) # Add the LinearRegionItem to the ViewBox, but tell the ViewBox to exclude this # item when doing auto-range calculations. self.region = pg.LinearRegionItem() self.region.setZValue(10) self.p2.addItem(self.region, ignoreBounds=True) self.p1.setAutoVisible(y=True) #plot data self.curve1 = self.p1.plot() self.curve2 = self.p2.plot() plot_tools.graph_pyqt(self.curve1, self.curve2, self.data, self.dataview) #axes plot_tools.change_display_pyqt(self.p1, self.dataview) plot_tools.change_display_pyqt(self.p2, self.dataview) #add line inspection tool self.vLine_2 = pg.InfiniteLine(angle=90, movable=False) self.p1.addItem(self.vLine_2, ignoreBounds=True) self.p1.scene().sigMouseMoved.connect(self.mouseMoved_graph) return self.win
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.plot_widget = pg.PlotWidget( title= "<font color = 'green'>Raw data</font>, <font color='red'>Baseline</font>", labels={ 'left': 'Ordinate', 'bottom': 'Abscissa' }) self.raw_data_item = pg.PlotDataItem(symbol='o', symbolBrush=pg.mkBrush('g'), symbolPen=None, pen=None, symbolSize=3, name='Raw data') self.baseline_data_item = pg.PlotDataItem(symbol='o', symbolBrush=pg.mkBrush('r'), symbolPen=None, pen=None, symbolSize=3, name='Baseline') self.data_bounds_region = pg.LinearRegionItem() self.data_bounds_region.hide() self.plot_widget.addItem(self.raw_data_item) self.plot_widget.addItem(self.baseline_data_item) self.plot_widget.addItem(self.data_bounds_region) layout = QtWidgets.QVBoxLayout() layout.addWidget(self.plot_widget) self.setLayout(layout)
def constructPlottingWidget(self): ''' Sets up both plotting views for the data viewer. ''' #Plot widget self.plotWidget = QtGui.QWidget() self.topPlot = pg.PlotWidget() self.plotLayout = QtGui.QGridLayout() self.bottomPlot = pg.PlotWidget() self.legend = self.topPlot.addLegend() for i in range(len(self.dataLabels)): self.topPlot.plot(self.xDatas[i],self.yDatas[i], pen=(i,len(self.dataLabels)),name=self.dataLabels[i]) self.bottomPlot.plot(self.xDatas[i],self.yDatas[i], pen=(i,len(self.dataLabels)),name=self.dataLabels[i]) self.bottomPlot.showGrid(x=True,y=True) #Set up highlighted reigon on top plot for zooming in on bottom plot self.hReigon = pg.LinearRegionItem([max(max(self.xDatas))*0.25,max(max(self.xDatas))*0.75]) self.hReigon.setBounds([0,max(max(self.xDatas))]) self.hReigon.sigRegionChanged.connect(self.onHReigonMove) #Add widgets for x,y values self.topPlot.addItem(self.hReigon) self.topPlot.setLabels(left=('Sensor units')) self.topPlot.setLabels(bottom=('Time (S)')) self.topPlot.setLabels(top=('Plot from: {}'.format(self.filePath))) self.plotLayout.addWidget(self.topPlot,0,0,1,2) self.plotLayout.addWidget(self.bottomPlot,2,0,1,2) self.plotWidget.setLayout(self.plotLayout)
def __init__(self, parent, device): super(miniscope, self).__init__(parent) self.setupUi(self) self.p = device self.A1Box.addItems(self.p.allAnalogChannels) self.splitter.setSizes([500, 100]) self.activeParameter = 0 self.curve = self.plot.plot(pen=colors[0]) self.fitcurve = self.plot.plot(pen=colors[1], width=2) self.curve2 = self.plot.plot(pen=colors[2]) self.fitcurve2 = self.plot.plot(pen=colors[3], width=2) self.region = pg.LinearRegionItem() self.region.setBrush([255, 0, 50, 50]) self.region.setZValue(10) for a in self.region.lines: a.setCursor(QtGui.QCursor(QtCore.Qt.SizeHorCursor)) self.plot.addItem(self.region, ignoreBounds=False) self.region.setRegion([.1, .5]) self.results = [] for a in [ 'amplitude', 'frequency', 'phase', 'offset', '', '', '', '', '', '' ]: x = QtWidgets.QListWidgetItem(a) self.list.addItem(x) self.results.append(None)
def __init__(self, parent=None, **kwargs): super(AppWindow, self).__init__(parent) self.setupUi(self) self.I = kwargs.get('I', None) from SEEL.analyticsClass import analyticsClass self.CC = analyticsClass() self.setWindowTitle(self.I.H.version_string + ' : ' + params.get('name', '').replace('\n', ' ')) self.plot1 = self.add2DPlot(self.plot_area) labelStyle = {'color': 'rgb(255,255,255)', 'font-size': '11pt'} self.plot1.setLabel('left', 'Voltage -->', units='V', **labelStyle) self.plot1.setLabel('bottom', 'Time -->', units='S', **labelStyle) self.plot1.setYRange(-8.5, 8.5) self.I.set_gain('CH1', 1) self.I.configure_trigger(0, 'CH1', 0) self.tg = 1 self.tgLabel.setText(str(5000 * self.tg * 1e-3) + 'mS') self.x = [] self.looptimer = self.newTimer() self.curveCH1 = self.addCurve(self.plot1, 'CH1') self.CH1Fit = self.addCurve(self.plot1, 'CH1 Fit') self.region = pg.LinearRegionItem([self.tg * 50, self.tg * 800]) self.region.setZValue(-10) self.plot1.addItem(self.region) self.lognum = 0 self.state = 0 self.I.set_state(SQR1=0) self.msg.setText("Fitting fn :\noff+amp*exp(-damp*x)*sin(x*freq+ph)") self.Params = []
def initMaskFunctionPlot(self): self.gccPHATPlotWidget = self.createGraphicsLayoutWidget( self.backgroundColor, contentMargins=(6, 12, 18, 10)) self.gccPHATPlotItem = self.gccPHATPlotWidget.addPlot() self.gccPHATPlotItem.getViewBox().setBackgroundColor( (255, 255, 255, 150)) self.gccPHATPlot = self.gccPHATPlotItem.plot() self.gccPHATPlot.setPen((0, 0, 0)) self.gccPHATPlotItem.hideAxis('left') self.gccPHATPlotItem.hideAxis('bottom') self.gccPHATPlotItem.hideButtons() self.gccPHATPlotItem.setXRange(0, self.numTDOAs - 1) self.targetTDOARegion = pg.LinearRegionItem( [ self.targetTDOAIndex - self.targetTDOAEpsilon, self.targetTDOAIndex + self.targetTDOAEpsilon ], bounds=[0, self.numTDOAs - 1], movable=True) self.targetTDOARegion.sigRegionChangeFinished.connect( self.tdoaRegionChanged) self.targetWindowFunctionPen = pg.mkPen( (0, 0, 204, 255), width=2) # , style=QtCore.Qt.DashLine) self.targetWindowFunctionPlot = TargetWindowFunctionPlot( self.targetTDOARegion, self.targetModeWindowTDOASlider, self.targetModeWindowBetaSlider, self.targetModeWindowNoiseFloorSlider, self.targetModeWindowWidthSlider, self.numTDOAs, pen=self.targetWindowFunctionPen) self.gccPHATPlotItem.addItem(self.targetWindowFunctionPlot) self.targetWindowFunctionPlot.updateData()
def __init__(self, parent): # items to highlight elements or regions in the graph self.oscSelectionRegion = pg.LinearRegionItem( [0, 0], movable=False, brush=self.SELECTED_ELEMENT_BRUSH) if QSignalDetectorWidget.visual_items_cache is None: QSignalDetectorWidget.visual_items_cache = VisualItemsCache() # the visual items for segmentation self.segmentation_visual_items = [] # the list of visual parameter items of every element. # Are stored separated because the elements are loaded lazy and # maybe the parameter for an element is supplied when its instance are not yet computed self.parameters_items = [] # the items for no visible elements list of tuples (item, visibility) self.no_visible_items = [] # list of detected sound lab elements. self._elements = [] # the visual items types visibility self.visual_items_visibility = VisualItemsVisibility() QSignalVisualizerWidget.__init__(self, parent)
def __init__(self, X, parent=None): super(HSIDialog, self).__init__(parent) self.setupUi(self) self.setWindowTitle('View Hyperspectral Data') if not isinstance(X, process.Process): raise TypeError( 'Data needs to be passed to skhyper.process.Process first') self._X = X self.shape = None self.dimensions = None self.slider.valueChanged.connect(self.update_layer) self.updateImage.clicked.connect(self.update_image) self.updateSpectrum.clicked.connect(self.update_spectrum) self.Reset.clicked.connect(self.reset) # --- Setting image/plot settings ----------------------- self.spec_lo = 0 self.spec_hi = 0 self.pgLRI = pg.LinearRegionItem() self.specwin.addItem(self.pgLRI) self.pgLRI.sigRegionChanged.connect(self.spec_region_updated) self.plotline = self.specwin.plot() # ------------------------------------------------------- self.load_data()
def add_lineout(self): ind=len(self.linear_regions)+1 xbounds=self.viewer.plotwidget.plotItem.vb.viewRange()[0] roi_bounds=np.linspace(xbounds[0],xbounds[1],4*ind+1) item=pg.LinearRegionItem([roi_bounds[4*ind-1],roi_bounds[4*ind]]) item.setZValue(-10) item.setBrush(QtGui.QColor(*self.color_list[ind-1])) item.setOpacity(0.2) self.linear_regions.append(item) self.viewer.plotwidget.plotItem.addItem(item) item.sigRegionChanged.connect(self.update_lineouts) item.sigRegionChangeFinished.connect(self.ROI_changed_finished.emit) item_lo=self.ui.Graph_Lineouts.plot() item_lo.setPen(QtGui.QColor(*self.color_list[ind-1])) self.lo_items.append(item_lo) child={'name': 'ROI_%02.0d' % ind, 'type': 'group', 'children': [ {'name': 'Color', 'type': 'color', 'value': QtGui.QColor(*self.color_list[ind-1])}, {'name': 'x1', 'type': 'float', 'value': item.getRegion()[0], 'step':1}, {'name': 'x2', 'type': 'float', 'value': item.getRegion()[0], 'step':1} ] } self.roi_settings.sigTreeStateChanged.disconnect(self.roi_tree_changed) self.roi_settings.child('ROIs').addChild(child) self.roi_settings.sigTreeStateChanged.connect(self.roi_tree_changed)
def initialize_plot(self): self.region = pg.LinearRegionItem(brush='#FF00FF20') self.region.setZValue(10) self.region.setRegion((0, 1.)) self.plot.addItem(self.region, ignoreBounds=True) self.region.sigRegionChanged.connect(self.on_region_changed) self.vline = pg.InfiniteLine(angle=90, movable=False, pen=self.params['vline_color']) self.vline.setZValue(1) # ensure vline is above plot elements self.plot.addItem(self.vline) self.rect_items = [] self.label_items = [] for i, label in enumerate(self.source.possible_labels): color = self.by_label_params['label' + str(i), 'color'] label_item = pg.TextItem(label, color=color, anchor=(0, 0.5), border=None, fill=self.params['label_fill_color']) label_item.setZValue(11) self.plot.addItem(label_item) self.label_items.append(label_item) self.viewBox.xsize_zoom.connect( self.params_controller.apply_xsize_zoom)
def Kline_plotting(self): #numd=self.data.df.reset_index() self.numd=self.data.code_data.reset_index() x=self.numd.date.apply(lambda x:datetime.datetime.strftime(x,"%Y-%m-%d")) self.xdict=dict(x) #转换成字符串字典 # LABEL 10个图标 self.maxRegion=len(self.numd.index) t=len(self.numd.index)//5 #提取坐标点 axis_date = [(i,list(x)[i]) for i in range(0,len(self.numd.index),t)] #stringaxis = pg.AxisItem(orientation='bottom') stringaxis = pg.AxisItem(orientation='bottom') #设置横轴 stringaxis.setTicks([axis_date, self.xdict.items()]) stringaxis.setGrid(255) stringaxis.setLabel( text='Dates' ) #stringaxis.setTickSpacing(100,1) self.k_plot = self.win.addPlot(row=1,col=0,title="kline",axisItems={'bottom': stringaxis}) self.y=self.numd.close self.k_plot.plot(x=list( self.xdict.keys()), y=self.y.values,pen=(0,255,255)) self.k_plot.showGrid(x=True, y=True) self.region = pg.LinearRegionItem() self.region.setZValue(self.maxRegion/4*3) self.region.setRegion([self.maxRegion/4*3, self.maxRegion]) self.k_plot.addItem(self.region , ignoreBounds=True)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.powder_pattern_viewer = pg.PlotWidget( title="Azimuthally-averaged pattern(s)", labels={ "left": "Intensity (counts)", "bottom": "Scattering vector (1/A)" }, ) self.time_series_widget = TimeSeriesWidget(parent=self) # Peak dynamics region-of-interest self.peak_dynamics_region = pg.LinearRegionItem(values=(0.2, 0.3)) self.peak_dynamics_region.sigRegionChanged.connect( self.update_peak_dynamics) self._text_height = 0 self.roi_left_text = pg.TextItem("", anchor=(1, 1)) self.roi_right_text = pg.TextItem("", anchor=(0, 1)) layout = QtWidgets.QVBoxLayout() layout.addWidget(self.powder_pattern_viewer) layout.addWidget(self.time_series_widget) self.setLayout(layout) self.resize(self.maximumSize())
def __init__(self, trace, tiffFig): super(TraceFig, self).__init__() self.tiffFig = tiffFig self.setWindowTitle('ceilingfaan - {}'.format( self.tiffFig.parent().settings.d['filename'])) self.setGeometry(QtCore.QRect(1000, 33, 905, 300)) self.label = pg.LabelItem(justify='right') self.addItem(self.label) self.p1 = self.addPlot(row=1, col=0) self.p2 = self.addPlot(row=2, col=0) self.region = pg.LinearRegionItem( ) # Add the LinearRegionItem to the ViewBox, but tell the ViewBox to exclude this item when doing auto-range calculations. self.region.setZValue(10) self.region.sigRegionChanged.connect(self.update) self.p1.sigRangeChanged.connect(self.updateRegion) self.p2.addItem(self.region, ignoreBounds=True) self.p1.setAutoVisible(y=True) self.trace = trace self.p1data = self.p1.plot(trace, pen="r") self.p2data = self.p2.plot(trace, pen=default_trace_color) self.vLine = pg.InfiniteLine(angle=90, movable=False) self.hLine = pg.InfiniteLine(angle=0, movable=False) self.p1.addItem(self.vLine, ignoreBounds=True) self.p1.addItem(self.hLine, ignoreBounds=True) self.vb = self.p1.vb self.proxy = pg.SignalProxy(self.p1.scene().sigMouseMoved, rateLimit=60, slot=self.mouseMoved) self.region.setRegion([0, 200]) self.p2.vb.mouseDragEvent = self.mouseDragEvent2 if self.tiffFig.parent().conditions is not None: self.update_gray_bars()
def mouseDoubleClickEvent(self, event: QMouseEvent) -> None: """ Differentiates mouse double clicks into creating a new region or deleting the old region. Parameters ---------- event : QMouseEvent The QMouseEvent occurs when the user double clicks the mouse button on the TIC widget """ super(TICWidget, self).mouseDoubleClickEvent(event) try: mouse_point = self.getViewBox().mapSceneToView(event.pos()) closest_datapoint_idx = self._calculate_closest_datapoint( mouse_point.x()) rgn_start = self._rts[closest_datapoint_idx] if self._region is None: region = pg.LinearRegionItem() region.setRegion((rgn_start, rgn_start)) self._region = region self.addItem(region, ignoreBounds=True) # delete the region when hovering over the region per doubleClk self._delete_region() except ValueError: print("No TIC values to click on")
def mouseDoubleClickEvent(self, event): super(WaveWidget, self).mouseDoubleClickEvent(event) x = self.mapToView(event.pos()).x() if not self.start_line and not self.current_rect: self.start_line = self.addLine(x=x, pen='g', name='start_line', movable=True) elif not self.current_rect: start = self.start_line.value() self.current_rect = pg.LinearRegionItem(values=[start, x], brush=(0, 255, 0, 100)) self.addItem(self.current_rect) self.removeItem(self.start_line) self.start_line = None self.player.setPlayRange((start, x)) else: left, right = self.current_rect.getRegion() if x < left: self.current_rect.setRegion((x, right)) self.player.setPlayRange((x, right)) elif x > right: self.current_rect.setRegion((left, x)) self.player.setPlayRange((left, x)) else: self.setWaveLabel()
def __init__(self, *args, **kwargs): super(InputSpectrogram, self).__init__(*args, **kwargs) viridis_lut = cmap_as_lut('viridis') self.p1 = self.addPlot() self.image_item_whole = pg.ImageItem() self.image_item_whole.setLookupTable(viridis_lut) self.lr = pg.LinearRegionItem([0, 500]) # self.lr.setZValue(-10) self.p1.addItem(self.image_item_whole) self.p1.addItem(self.lr) self.p1.showAxis('left', False) self.p1.setMaximumHeight(50) self.nextRow() self.p2 = self.addPlot() self.image_item_sub = pg.ImageItem() self.image_item_sub.setLookupTable(viridis_lut) self.p2.addItem(self.image_item_sub, ) self.p2.showAxis('left', False) self.ci.setSpacing(0) # self.updatePlot() self.p2.sigXRangeChanged.connect(self.updateRegion) self.lr.sigRegionChanged.connect(self.updatePlot) # TODO: add click event to move region instead of only dragging # i.e. that way if region goes off screen, can still move self.p1.scene().sigMouseClicked.connect(self.on_mouse_click)
def __init__(self, parent=None): super(waveform, self).__init__(parent) self._waveFile = { 'path': "", 'framerate': "", 'nchannels': "", 'sample_width': "", 'nframes': "" } layout = QVBoxLayout(self) pg.setConfigOption('background', 'w') pg.setConfigOption('foreground', 'k') self.pw = pg.PlotWidget() self.pw.plot([-0.1, 0.1], pen='b') layout.addWidget(self.pw) self.selectionCtrl = pg.LinearRegionItem([50, 10000]) self.selectionCtrl.setZValue(-10) self.loadAudioAction = QAction("Load Audio File (*.wav)", self) self.loadAudioAction.triggered.connect(self.load_wavFile) self.extAudioAction = QAction("Extract Audio File (*.wav)", self) self.extAudioAction.triggered.connect(self.extract_wavFile) self.selectRegion = QAction("Select Region", self) self.selectRegion.triggered.connect(self.activateRegion) self.remSelection = QAction("Disable Selection", self) self.remSelection.triggered.connect(self.deactivateRegion)
def createFreqRegions(self, values=[[0.02, 0.07], [0.07, 0.20], [0.20, 0.50]], colors=['#d5e5ff', '#d7f4d7', '#ffe6d5']): alpha = '80' for i in range(len(values)): selection = pg.LinearRegionItem(values=values[i], orientation=pg.LinearRegionItem.Vertical, movable=False, brush=pg.mkBrush(color=colors[i] + alpha)) selection.setZValue(-10) self.addItem(selection, ignoreBounds=True)
def drawHistogram(self, values, xmin, xmax, bins): # compute the histogram if bins >= 50: bin = 51 else: bin = bins + 1 y, x = np.histogram(values, bins=np.linspace(xmin, xmax, num=bin)) # plot the chart if has_pyqtgraph: curve = pg.PlotCurveItem() self.plot.clear() curve.setData(x, y, stepMode=True, fillLevel=0, brush=(230, 230, 230), pen=pg.mkPen(None)) self.plot.addItem(curve) # add the selection tool self.region = pg.LinearRegionItem([xmax, xmax], bounds=[xmin, xmax]) self.region.sigRegionChangeFinished.connect( self.changedHistogramSelection) if self.show_lines: self.plot.addItem(self.region) # add the selection plot self.clearHistogramSelection() self.hist_selection = pg.PlotCurveItem() self.plot.addItem(self.hist_selection)