def __init__(self, *args, **kwargs) -> None: super(DataLabel, self).__init__(*args, **kwargs) header = pg.LabelItem(style.data_label('Data range')) max_prefix = pg.LabelItem(style.data_label('Max:'), justify='left') min_prefix = pg.LabelItem(style.data_label('Min:'), justify='left') range_prefix = pg.LabelItem(style.data_label('Max - Min:'), justify='left') self.max_label = pg.LabelItem(style.data_label(str(0)), justify='left') self.min_label = pg.LabelItem(style.data_label(str(0)), justify='left') self.delta_label = pg.LabelItem(style.data_label(str(0)), justify='left') self.layout = QtWidgets.QGraphicsGridLayout() self.layout.setContentsMargins(1, 1, 1, 1) self.layout.setSpacing(0) self.layout.addItem(header, 0, 0, 1, 2) self.layout.addItem(max_prefix, 1, 0) self.layout.addItem(self.max_label, 1, 1) self.layout.addItem(min_prefix, 2, 0) self.layout.addItem(self.min_label, 2, 1) self.layout.addItem(range_prefix, 3, 0) self.layout.addItem(self.delta_label, 3, 1) self.layout.setColumnStretchFactor(0, 2) self.layout.setColumnStretchFactor(1, 1) self.setLayout(self.layout) self.setToolTip('データ範囲表示')
def __init__(self, *args, **kwargs) -> None: super(GraphTitleLabel, self).__init__(*args, **kwargs) title_prefix = pg.LabelItem(style.graph_title('Image Title:'), justify='left') cross_section = pg.LabelItem(style.graph_title('Cross section'), justify='left') hcs_prefix = pg.LabelItem(style.graph_title('Y:'), justify='left') vcs_prefix = pg.LabelItem(style.graph_title('X:'), justify='left') self.title = pg.LabelItem(justify='left') self.hcs = pg.LabelItem(justify='left') self.vcs = pg.LabelItem(justify='left') self.layout = QtWidgets.QGraphicsGridLayout() self.layout.setContentsMargins(1, 1, 1, 1) self.layout.setSpacing(0) self.layout.addItem(title_prefix, 0, 0) self.layout.addItem(self.title, 0, 1) self.layout.addItem(cross_section, 0, 2) self.layout.addItem(vcs_prefix, 0, 3) self.layout.addItem(self.vcs, 0, 4) self.layout.addItem(hcs_prefix, 0, 5) self.layout.addItem(self.hcs, 0, 6) self.setLayout(self.layout) self.layout.setColumnStretchFactor(1, 4) self.layout.setColumnStretchFactor(4, 1) self.layout.setColumnStretchFactor(6, 1)
def __init__(self, size=None, offset=None, horSpacing=25, verSpacing=0, box=True, labelAlignment='center', showLines=True): """ ============== =============================================================== **Arguments:** size Specifies the fixed size (width, height) of the legend. If this argument is omitted, the legend will autimatically resize to fit its contents. offset Specifies the offset position relative to the legend's parent. Positive values offset from the left or top; negative values offset from the right or bottom. If offset is None, the legend must be anchored manually by calling anchor() or positioned by calling setPos(). horSpacing Specifies the spacing between the line symbol and the label. verSpacing Specifies the spacing between individual entries of the legend vertically. (Can also be negative to have them really close) box Specifies if the Legend should will be drawn with a rectangle around it. labelAlignment Specifies the alignment of the label texts. Possible values are "center", "left" or "right". showLines Specifies whether or not the lines should be shown in the legend. If value is "False" it will only show the labels with the corresponding text color. ============== =============================================================== """ GraphicsWidget.__init__(self) GraphicsWidgetAnchor.__init__(self) self.setFlag(self.ItemIgnoresTransformations) self.layout = QtWidgets.QGraphicsGridLayout() self.layout.setVerticalSpacing(verSpacing) self.layout.setHorizontalSpacing(horSpacing) self._horSpacing = horSpacing self._verSpacing = verSpacing self.setLayout(self.layout) self.legendItems = [] self.plotItems = [] self.hiddenFlag = [] self.size = size self.offset = offset self.box = box self.label_alignment = labelAlignment self.showLines = showLines # A numItems variable needs to be introduced, because chaining removeItem and addItem function in random order, # will otherwise lead to writing in the same layout row. Idea here is to always insert LabelItems on larger # and larger layout row numbers. The GraphicsGridlayout item will not care about empty rows. self.numItems = 0 if size is not None: self.setGeometry(QtCore.QRectF(0, 0, self.size[0], self.size[1]))
def __init__(self, title: str = '', bar_label: str = '', *args, **kwargs) -> None: """初期化処理 Parameters ---------- title: str default='' グラフタイトル bar_label: str default='' カラーバーラベル """ super(ColormapWidget, self).__init__(*args, **kwargs) self.image = pg.ImageItem(axisOrder='row-major') self.image.setLookupTable(self.make_lookup_table()) self.view_box = pg.ViewBox(lockAspect=True) self.view_box.addItem(self.image) self.xaxis = XImageAxis() self.yaxis = YImageAxis() self.plot = pg.PlotItem(viewBox=self.view_box, axisItems={'bottom': self.xaxis, 'left': self.yaxis, }) self.plot.setTitle(title) self.plot.setLabels(bottom='X', left='Y') self.coord = CoordScatter() self.coord.setZValue(10) self.plot.addItem(self.coord) self.hcs_line = pg.InfiniteLine(angle=0, movable=True, pen=pg.mkPen('#fff')) self.vcs_line = pg.InfiniteLine(angle=90, movable=True, pen=pg.mkPen('#fff')) self.plot.addItem(self.hcs_line, ignoreBounds=True) self.plot.addItem(self.vcs_line, ignoreBounds=True) self.hcs_line.setZValue(20) self.vcs_line.setZValue(20) self.color_bar = ColorLegendItem(imageItem=self.image, label=bar_label) self.layout = QtWidgets.QGraphicsGridLayout() self.layout.setContentsMargins(1, 1, 1, 1) self.layout.setSpacing(0) self.layout.addItem(self.plot, 0, 0) self.layout.addItem(self.color_bar, 0, 2) self.setLayout(self.layout) self.hcs_line.sigPositionChanged.connect(self.get_hcross_section) self.vcs_line.sigPositionChanged.connect(self.get_vcross_section)
# Overlay viewbox that will have alway have the same geometry as the colorScaleViewBox overlayViewBox = pg.ViewBox(enableMenu=False, border=pg.mkPen(pg.getConfigOption('foreground'), width=1)) overlayViewBox.setZValue(100) axisItem = pg.AxisItem(orientation='right', linkView=overlayViewBox, showValues=True, parent=view) # Overall layout from PyQt5 import QtWidgets mainLayout = QtWidgets.QGraphicsGridLayout() pg_wid = pg.GraphicsWidget(parent=view) pg_wid.setLayout(mainLayout) mainLayout.setContentsMargins(1, 1, 1, 1) mainLayout.setSpacing(0) mainLayout.addItem(colorScaleViewBox, 0, 1) # mainLayout.addItem(colorScaleImageItem, 0, 1) mainLayout.addItem(axisItem, 0, 2) overlayViewBox.setParentItem(colorScaleViewBox.parentItem()) ## Start Qt event loop unless running in interactive mode. if __name__ == '__main__': import sys if (sys.flags.interactive != 1) or not hasattr(pg.QtCore, 'PYQT_VERSION'): pg.QtGui.QApplication.instance().exec_()
def __init__(self, x, y): super(BandSelectorWidget, self).__init__() # parameters self.width = 3 self.x = 20 self.x_max = 30. self.gran = x[1] - x[0] graphics_widget = pg.GraphicsWidget() self.middle = pg.LinearRegionItem([self.x, self.x], pg.LinearRegionItem.Vertical) self.middle.setBounds( [0 + self.width / 2, self.x_max - self.width / 2]) self.middle.sigRegionChanged.connect(self.regionChanged) self.region = pg.LinearRegionItem( [self.x - self.width / 2, self.x + self.width / 2], pg.LinearRegionItem.Vertical, movable=False) self.region.setBounds((0, self.x_max)) self.region.sigRegionChanged.connect(self.regionChanged) view_box = pg.ViewBox(parent=graphics_widget, enableMouse=False, enableMenu=False) #view_box.setAspectLocked() view_box.setYRange(0, 1) #view_box.enableAutoRange(view_box.XYAxes) axis = pg.AxisItem('bottom', linkView=view_box, parent=graphics_widget) plot = pg.PlotDataItem() plot.setData(x, y / (max(y[x < self.x_max]) or 1)) view_box.setXRange(0, self.x_max) view_box.addItem(plot) view_box.addItem(self.region) view_box.addItem(self.middle) self.view_box = view_box # setup grid layout grid_layout = QtWidgets.QGraphicsGridLayout(graphics_widget) grid_layout.addItem(axis, 1, 0) grid_layout.addItem(view_box, 0, 0) # view view = pg.GraphicsView() view.setCentralItem(graphics_widget) self.width_slider = ParameterSlider('Band width:', 1, 10, interval=0.1, value=self.width, units='Hz') self.width_slider.valueChanged.connect(self.changeWidth) main_layout = QtWidgets.QVBoxLayout(self) main_layout.addWidget(view) main_layout.addWidget(self.width_slider) self.band = None btn = QtWidgets.QPushButton('Select') btn.clicked.connect(self.select_band) btn.setMaximumWidth(200) self.band_str = QtWidgets.QLabel( 'Band:\t{}\t-\t{} Hz'.format(*self.region.getRegion())) main_layout.addWidget(self.band_str) main_layout.addWidget(btn)