def __init__(self, main_widget, histogram=True, crop_selector=False): super().__init__() self.main_widget = main_widget # self.setMinimumWidth(600) # self.setMinimumHeight(300) # self.setStyleSheet("ImageViewModule {margin:5px; border:1px solid rgb(50, 65, " # "75);} ") self.setStyleSheet("ImageViewModule {margin:0px; border:0px solid rgb(50, 65, " "75); padding: 0px;} ") self.layout = QVBoxLayout() self.layout.setContentsMargins(0, 0, 0, 0) # self.layout.setAlignment(Qt.AlignHCenter) self.image_label = QLabel() self.layout.addWidget(self.image_label) self.setLayout(self.layout) # self.already_loaded = True # self.no_image_message = QPushButton("Please open a dataset first") # self.no_image_message.clicked.connect(main_widget.open_file_dialog) # self.no_image_message.setStyleSheet("QPushButton {font-size:80;}") self.image_view = ImageView(view=PlotItem()) self.image_view.keyPressEvent = self.keyPressEvent self.image_view.ui.layoutWidget.setContentsMargins(0, 0, 0, 0) # self.image_view.ui.roiBtn.hide() self.image_view.ui.menuBtn.hide() if not histogram: self.image_view.ui.histogram.hide() if not crop_selector: self.image_view.ui.roiBtn.hide() # self.image_view.getRoiPlot().hide() self.image_item = self.image_view.getImageItem() self.layout.addWidget(self.image_view)
def __init__(self, parent=None, image_channel=None, width_channel=None): """Initialize widget.""" # Set the default colormap. self._colormap = PyDMColorMap.Inferno self._cm_colors = None self._imagechannel = None self._widthchannel = None self.image_waveform = np.zeros(0) self._image_width = 0 self._normalize_data = False self._auto_downsample = True self._show_axes = False # Set default reading order of numpy array data to Fortranlike. self._reading_order = ReadingOrder.Fortranlike self._redraw_rate = 30 # Set color map limits. self.cm_min = 0.0 self.cm_max = 255.0 plot_item = PlotItem() ImageView.__init__(self, parent, view=plot_item) PyDMWidget.__init__(self) self._channels = [None, None] self.thread = None self.axes = dict({'t': None, "x": 0, "y": 1, "c": None}) self.showAxes = self._show_axes self.imageItem.setOpts(axisOrder="row-major") # Hide some itens of the widget. self.ui.histogram.hide() self.getImageItem().sigImageChanged.disconnect( self.ui.histogram.imageChanged) self.ui.roiBtn.hide() self.ui.menuBtn.hide() # Make a right-click menu for changing the color map. self.cm_group = QActionGroup(self) self.cmap_for_action = {} for cm in self.color_maps: action = self.cm_group.addAction(cmap_names[cm]) action.setCheckable(True) self.cmap_for_action[action] = cm self.colorMap = self._colormap # Setup the redraw timer. self.needs_redraw = False self.redraw_timer = QTimer(self) self.redraw_timer.timeout.connect(self.redrawImage) self.maxRedrawRate = self._redraw_rate self.newImageSignal = self.getImageItem().sigImageChanged # Set live channels if requested on initialization if image_channel: self.imageChannel = image_channel or '' if width_channel: self.widthChannel = width_channel or ''
def create_plots(self): self.plotDict = { "plotItem": PlotItem(), "plotDataItem": None, "displayed": 1 } self.pyqtgraphWidget.addItem(self.plotDict["plotItem"]) self.plotDict["plotDataItem"] = self.plotDict["plotItem"].plot()
def createGraph(self, data, graph): plot = PlotItem() line = PlotCurveItem(x=asarray( [x for x in range(0, self.element.sections + 1)]), y=data, pxMode=True, symbolSize=5) plot.addItem(line) graph.addItem(plot, row=0, col=0)
def __init__(self, layout, range, *args, **kwargs): self.plot_view = PlotItem(lockAspect=1) super(ImagePlot, self).__init__(*args, view=self.plot_view, **kwargs) layout.insertWidget(0, self) self.setup(range) self.show()
def __init__(self, dbeta, rh): self.dbeta = dbeta self.p4main = glo_var.MyPW(x="\u03b2", y1="J", y2="\u27e8\u2374\u27e9", set_range=self.set_range) # self.p4main._rescale = self.set_range self.p4 = self.p4main.plotItem self.viewbox = self.p4.getViewBox() # self.viewbox.setBackgroundColor('w') self.item = self.p4 self.p4main.tempplotitem = PlotItem() self.p4_2 = self.p4main.tempplotitem.vb self.p4.setLabel('left', "J", **glo_var.labelstyle) self.p4.setLabel('bottom', "\u03b2", **glo_var.labelstyle) self.p4.setLabel('right', "\u27e8\u2374\u27e9", **glo_var.labelstyle) # self.p4main.set_range = self.set_range self.rh = rh self.rho_dash = mkPen(color=(16, 52, 166), width=glo_var.line_width, style=QtCore.Qt.DashLine) self.dash = mkPen('r', width=glo_var.line_width, style=QtCore.Qt.DashLine) self.jpen = mkPen('k', width=glo_var.line_width) self.beta_pen = mkPen('k', width=glo_var.line_width) self.p4.addLegend = glo_var.myaddLegend self.p4.addLegend(self.p4, offset=(20, 20)) self.p4.showAxis('right') self.p4.scene().addItem(self.p4_2) self.p4.getAxis('right').linkToView(self.p4_2) self.p4_2.setXLink(self.p4) self.p4_2.setBackgroundColor('w') self.p4main.coordinate_label = QtGui.QLabel() self.frame = glo_var.setframe( self.p4main, width=1, coordinate_label=self.p4main.coordinate_label) self.dbeta.addWidget(self.frame) self.viewbox.setLimits(xMin=0, yMin=0, xMax=1, yMax=1) self.p4_2.setLimits(xMin=0, yMin=0, xMax=1, yMax=1) self.p4.vb.sigResized.connect(self.updateview) self.update() self.legend()
def __init__(self, layout, x, y, *args, **kwargs): self.plot_view = PlotItem() super(SurfacePlot, self).__init__(*args, **kwargs) layout.insertWidget(0, self) self.image = None self.setup(x, y) self.show()
def __init__(self, *args, plot_data=None, **kwargs): # Setup GUI self.plot_view = PlotItem() super(PyQtGraphPlot, self).__init__( *args, view=self.plot_view, **kwargs) self._setup() self.model = PyQtGraphPlotModel(plot_data) self.refresh_plot()
def __init__(self, header: NonDBHeader = None, field: str = 'primary', toolbar: QToolBar = None, *args, **kwargs): # Add axes self.axesItem = PlotItem() # self.axesItem.setLabel('bottom', u'q ()') # , units='s') # self.axesItem.setLabel('bottom', u'q ()') # , units='s') # self.axesItem.setLabel('left', u'q ()') self.axesItem.axes['left']['item'].setZValue(10) self.axesItem.axes['top']['item'].setZValue(10) if 'view' not in kwargs: kwargs['view'] = self.axesItem super(EFIViewerPlugin, self).__init__(**kwargs) self.axesItem.invertY(True) # Setup axes reset button self.resetAxesBtn = QPushButton('Reset Axes') sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(1) sizePolicy.setHeightForWidth( self.resetAxesBtn.sizePolicy().hasHeightForWidth()) self.resetAxesBtn.setSizePolicy(sizePolicy) self.resetAxesBtn.setObjectName("resetAxes") self.ui.gridLayout.addWidget(self.resetAxesBtn, 2, 1, 1, 1) self.resetAxesBtn.clicked.connect(self.autoRange) # Setup LUT reset button self.resetLUTBtn = QPushButton('Reset LUT') sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(1) sizePolicy.setHeightForWidth( self.resetLUTBtn.sizePolicy().hasHeightForWidth()) # self.resetLUTBtn.setSizePolicy(sizePolicy) # self.resetLUTBtn.setObjectName("resetLUTBtn") self.ui.gridLayout.addWidget(self.resetLUTBtn, 3, 1, 1, 1) self.resetLUTBtn.clicked.connect(self.autoLevels) # Hide ROI button and rearrange # self.ui.roiBtn.setParent(None) # self.ui.gridLayout.addWidget(self.ui.menuBtn, 1, 1, 1, 1) # self.ui.gridLayout.addWidget(self.ui.graphicsView, 0, 0, 3, 1) # Setup coordinates label # self.coordinatesLbl = QLabel('--COORDINATES WILL GO HERE--') # self.ui.gridLayout.addWidget(self.coordinatesLbl, 3, 0, 1, 1, alignment=Qt.AlignHCenter) # Set header if header: self.setHeader(header, field)
def __init__(self, *args, **kwargs): # Add axes self.axesItem = PlotItem() self.axesItem.axes["left"]["item"].setZValue(10) self.axesItem.axes["top"]["item"].setZValue(10) if "view" not in kwargs: kwargs["view"] = self.axesItem super(XArrayView, self).__init__(*args, **kwargs) self.view.invertY(False)
def __init__(self, *args, **kwargs): # Add axes self.axesItem = PlotItem() self.axesItem.axes["left"]["item"].setZValue(10) self.axesItem.axes["top"]["item"].setZValue(10) if "view" not in kwargs: kwargs["view"] = self.axesItem self._transform = QTransform() super(PixelSpace, self).__init__(*args, **kwargs) self.imageItem.sigImageChanged.connect(self.updateAxes)
def create_plots(self): self.allPlotsDict["plot"] = {"plotItem": PlotItem(), "displayed": 1} #self.allPlotsDict["plot"]["plotItem"].setXRange(0, 30000) red = mkColor('r') blue = mkColor('b') green = mkColor('g') dataPlotItem = self.allPlotsDict["plot"]["plotItem"].plot(pen=mkPen(red, width=2)) self.allPlotsDict["plot"]["voltage"] = dataPlotItem dataPlotItem = self.allPlotsDict["plot"]["plotItem"].plot(pen=mkPen(blue, width=2)) self.allPlotsDict["plot"]["current"] = dataPlotItem dataPlotItem = self.allPlotsDict["plot"]["plotItem"].plot(pen=mkPen(green, width=2)) self.allPlotsDict["plot"]["temperature"] = dataPlotItem self.pyqtgraphWidget.addItem(self.allPlotsDict["plot"]["plotItem"])
def create_plots(self): for indicator in Person().indicators: self.allPlotsDict[indicator] = { "plotItem": PlotItem(), "displayed": 0 } for indicator in Person().indicators: self.allPlotsDict[indicator]["plotDataItem"] = {} for ageGroup in Person().ageGroupsList: dataPlotItem = self.allPlotsDict[indicator]["plotItem"].plot() self.allPlotsDict[indicator]["plotDataItem"][ ageGroup] = dataPlotItem # self.allPlotsDict[indicator]["plotDataItem"][ageGroup].setDownsampling() self.allPlotsDict[indicator]["plotItem"].setTitle(indicator) print(self.allPlotsDict)
def __init__(self, model, video_model=None, parent=None, colormap="inferno"): """ Sets the datamodel and optionally a videomodel that is used to print a time indicator according to its current frameself. Args: model: DataModel wrapping either 1d or 2d data video_model: VideoModel wrapping a video file parent: Parent QtWidget colormap: String describing matplotlib colormap """ self.view = PlotItem() super().__init__(view=self.view) self.model = model self.video_model = video_model self.print_indicator = False self.indicator = None # Get a colormap colormap = plt.cm.get_cmap( colormap) # cm.get_cmap("CMRmap")nipy_spectral colormap._init() self.lut = (colormap._lut * 255).view( np.ndarray ) # Convert matplotlib colormap from 0-1 to 0 -255 for Qt self.ui.histogram.hide() self.ui.roiBtn.hide() self.ui.menuBtn.hide() initial_data = self.model.get_data() if not isinstance(initial_data, type(None)): #Draw imagedata if possible try: self.print_data(initial_data) except: #It might be that the model contains data that is not displayable e.g. 1d pass
def __init__(self, parent, shared_data): super(DataWidget, self).__init__(parent) self.__shared_data = shared_data self.__shared_data.update_sync.emit() # Add the file selection controls self.__dir_picker_button = QPushButton() self.__dir_picker_button.setEnabled(True) self.__dir_picker_button.setText("Load data") self.__dir_picker_button.setIcon(self.style().standardIcon(QStyle.SP_DirIcon)) self.__dir_picker_button.setToolTip('Select the directory using the file explorer') self.__dir_picker_button.clicked.connect(self.__open_dir_picker) # Add the sync controls self.__sync_time_label = QLabel() self.__sync_time_label.setText('Enter the timecode (HH:mm:ss:zzz) : ') self.__sync_time_edit = QTimeEdit() self.__sync_time_edit.setDisplayFormat('HH:mm:ss:zzz') self.__sync_time_edit.setEnabled(False) self.__sync_time_button = QPushButton() self.__sync_time_button.setText('Sync data') self.__sync_time_button.setEnabled(False) self.__sync_time_button.clicked.connect(self.__sync_data) # Create the layout for the file controls dir_layout = QHBoxLayout() dir_layout.setContentsMargins(0, 0, 0, 0) dir_layout.addWidget(self.__dir_picker_button) dir_layout.addStretch(1) dir_layout.addWidget(self.__sync_time_label) dir_layout.addWidget(self.__sync_time_edit) dir_layout.addWidget(self.__sync_time_button) # Create the axis and their viewbox self.__x_axis_item = AxisItem('left') self.__y_axis_item = AxisItem('left') self.__z_axis_item = AxisItem('left') self.__x_axis_viewbox = ViewBox() self.__y_axis_viewbox = ViewBox() self.__z_axis_viewbox = ViewBox() # Create the widget which will display the data self.__graphic_view = GraphicsView(background="#ecf0f1") self.__graphic_layout = GraphicsLayout() self.__graphic_view.setCentralWidget(self.__graphic_layout) # Add the axis to the widget self.__graphic_layout.addItem(self.__x_axis_item, row=2, col=3, rowspan=1, colspan=1) self.__graphic_layout.addItem(self.__y_axis_item, row=2, col=2, rowspan=1, colspan=1) self.__graphic_layout.addItem(self.__z_axis_item, row=2, col=1, rowspan=1, colspan=1) self.__plot_item = PlotItem() self.__plot_item_viewbox = self.__plot_item.vb self.__graphic_layout.addItem(self.__plot_item, row=2, col=4, rowspan=1, colspan=1) self.__graphic_layout.scene().addItem(self.__x_axis_viewbox) self.__graphic_layout.scene().addItem(self.__y_axis_viewbox) self.__graphic_layout.scene().addItem(self.__z_axis_viewbox) self.__x_axis_item.linkToView(self.__x_axis_viewbox) self.__y_axis_item.linkToView(self.__y_axis_viewbox) self.__z_axis_item.linkToView(self.__z_axis_viewbox) self.__x_axis_viewbox.setXLink(self.__plot_item_viewbox) self.__y_axis_viewbox.setXLink(self.__plot_item_viewbox) self.__z_axis_viewbox.setXLink(self.__plot_item_viewbox) self.__plot_item_viewbox.sigResized.connect(self.__update_views) self.__x_axis_viewbox.enableAutoRange(axis=ViewBox.XAxis, enable=True) self.__y_axis_viewbox.enableAutoRange(axis=ViewBox.XAxis, enable=True) self.__z_axis_viewbox.enableAutoRange(axis=ViewBox.XAxis, enable=True) # Create the final layout self.__v_box = QVBoxLayout() self.__v_box.addLayout(dir_layout) self.__v_box.addWidget(self.__graphic_view) self.setLayout(self.__v_box) self.__restore_state()
def purge(self): self.plot = PlotItem()
def __init__(self, datablock): super().__init__(datablock) self.plot = PlotItem() self.plot.addLegend()
def __init__(self, header: NonDBHeader = None, field: str = 'primary', toolbar: QToolBar = None, *args, **kwargs): # Add q axes self.axesItem = PlotItem() self.axesItem.setLabel('bottom', u'q (Å⁻¹)') # , units='s') self.axesItem.setLabel('left', u'q (Å⁻¹)') self.axesItem.axes['left']['item'].setZValue(10) self.axesItem.axes['top']['item'].setZValue(10) if 'view' not in kwargs: kwargs['view'] = self.axesItem super(SAXSViewerPlugin, self).__init__(**kwargs) self.axesItem.invertY(False) # Setup axes reset button self.resetAxesBtn = QPushButton('Reset Axes') sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(1) sizePolicy.setHeightForWidth( self.resetAxesBtn.sizePolicy().hasHeightForWidth()) self.resetAxesBtn.setSizePolicy(sizePolicy) self.resetAxesBtn.setObjectName("resetAxes") self.ui.gridLayout.addWidget(self.resetAxesBtn, 2, 1, 1, 1) self.resetAxesBtn.clicked.connect(self.autoRange) # Setup LUT reset button self.resetLUTBtn = QPushButton('Reset LUT') sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(1) sizePolicy.setHeightForWidth( self.resetLUTBtn.sizePolicy().hasHeightForWidth()) # self.resetLUTBtn.setSizePolicy(sizePolicy) # self.resetLUTBtn.setObjectName("resetLUTBtn") self.ui.gridLayout.addWidget(self.resetLUTBtn, 3, 1, 1, 1) self.resetLUTBtn.clicked.connect(self.autoLevels) # Hide ROI button and rearrange self.ui.roiBtn.setParent(None) self.ui.gridLayout.addWidget(self.ui.menuBtn, 1, 1, 1, 1) self.ui.gridLayout.addWidget(self.ui.graphicsView, 0, 0, 3, 1) # Setup coordinates label self.coordinatesLbl = QLabel('--COORDINATES WILL GO HERE--') self.ui.gridLayout.addWidget(self.coordinatesLbl, 3, 0, 1, 1, alignment=Qt.AlignHCenter) # Setup mask layer self.maskimage = pg.ImageItem(opacity=.25) self.view.addItem(self.maskimage) # Setup calibration layer self.calibrantimage = pg.ImageItem(opacity=.25) self.view.addItem(self.calibrantimage) # Empty ROI for later use self.maskROI = pg.PolyLineROI([], closed=True, movable=False, pen=pg.mkPen(color='r', width=2)) self.maskROI.handlePen = pg.mkPen(color='r', width=2) self.maskROI.handleSize = 10 self.view.addItem(self.maskROI) # Connect toolbar handlers self.toolbar = toolbar if self.toolbar: self.toolbar.modegroup.triggered.connect(self.redraw) # Setup results cache self.results = [] # Set header if header: self.setHeader(header, field)
def __init__(self): GraphicsView.__init__(self) # create layout self.layout = pg.GraphicsLayout() self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setSpacing(-1.) self.setBackground(None) self.setCentralItem(self.layout) # create axes and apply formatting axisItems = dict() for pos in ['bottom', 'left', 'top', 'right']: axisItems[pos] = AxisItem(orientation=pos, maxTickLength=-7) self.p = PlotItem(axisItems=axisItems) self.setTitle('Sweep data', fontScaling=1.3, color='k') self.layout.addItem(self.p) self.p.vb.setBackgroundColor('w') self.p.setContentsMargins(10, 10, 10, 10) for pos in ['bottom', 'left', 'top', 'right']: ax = self.p.getAxis(pos) ax.setZValue(0) # draw on top of patch ax.setVisible(True) # make all axes visible ax.setPen(width=self.LW * 2 / 3, color=0.5) # grey spines and ticks try: ax.setTextPen('k') # black text except AttributeError: pass ax.setStyle(autoExpandTextSpace=True, tickTextOffset=4) self.p.getAxis('top').setTicks([]) self.p.getAxis('top').setHeight(0) self.p.getAxis('right').setTicks([]) self.x_axis = self.p.getAxis('bottom') self.y_axis = self.p.getAxis('left') self.x_axis.setLabel('Voltage', units='V', color='k', size='12pt') self.y_axis.setLabel('Current', units='A', color='k', size='12pt') self.y_axis.setStyle(tickTextWidth=35) # set auto range and mouse panning / zooming self.p.enableAutoRange(x=True, y=True) self.p.setLimits(xMin=-1e20, xMax=1e20, yMin=-1e20, yMax=1e20) def suggestPadding(axis): length = self.p.vb.width() if axis == 0 else self.p.vb.height() if length > 0: if axis == 0: padding = 0 else: padding = np.clip(1. / (length**0.5), 0.02, 0.1) else: padding = 0.02 return padding self.p.vb.suggestPadding = suggestPadding # set default ranges to start self.p.setXRange(-10, 10) self.p.setYRange(-10, 10) # add legend self.legend = LegendItem(brush=fn.mkBrush(255, 255, 255, 150), labelTextColor='k', offset=(20, -20)) self.legend.setParentItem(self.p.vb)
app = QtGui.QApplication([]) window = QMainWindow() holder = QWidget() holder_layout = QGridLayout() holder.setLayout(holder_layout) window.setCentralWidget(holder) # # Grid section # grid_widget = pg.GraphicsLayoutWidget() grid_viewBox1 = ViewBox(enableMenu=True) grid_viewBox1.setXRange(0, 5, padding=0) grid_viewBox1.setYRange(0, 2.5, padding=0) grid_subplot1 = PlotItem(viewBox=grid_viewBox1) grid_subplot1.showGrid(True, True, 0.2) grid_viewBox1.setParent(grid_subplot1) grid_widget.addItem(grid_subplot1, col=0, row=0) grid_viewBox2 = ViewBox(enableMenu=True) grid_viewBox2.setXRange(0, 5, padding=0) grid_viewBox2.setYRange(0, 2.5, padding=0) grid_subplot2 = PlotItem(viewBox=grid_viewBox2) grid_subplot2.showGrid(True, True, 0.2) grid_viewBox2.setParent(grid_subplot2) grid_widget.addItem(grid_subplot2, col=1, row=0) grid_viewBox3 = ViewBox(enableMenu=True) grid_viewBox3.setXRange(0, 5, padding=0) grid_viewBox3.setYRange(0, 2.5, padding=0)
def create_plots(self): self.plotDict["plotItem"] = PlotItem() # self.plotDict["plotDataItem"] = self.plotDict["plotItem"].plot() self.pyqtgraphWidget.addItem(self.plotDict["plotItem"]) self.plotDict["BarGraphItem"] = None