def __init__(self, parent=None): super().__init__(parent) self.layout = QtGui.QGraphicsGridLayout() self.setLayout(self.layout) self.gradient = pg.GradientEditorItem(orientation="right") self.axis = pg.AxisItem(orientation="left") self.layout.addItem(self.gradient, 0, 1) self.layout.addItem(self.axis, 0, 0)
def __init__(self, parent=None, image=None, label=None, images=()): pg.GraphicsWidget.__init__(self, parent) """Previous version used manual layout. This worked for initial setup but I couldn't figure out how to make it update automatically if e.g. the axis width changed. So switched to layout management. This requires the ImageItem to be in a QGraphicsLayoutItem, since it is not one itself. Putting it in a ViewBox seemed the simplest option.""" # Backwards compatilbility: retain image argument if image is not None: assert images == () images = (image, ) images = tuple(images) # Setup layout self.layout = QtGui.QGraphicsGridLayout() self.layout.setHorizontalSpacing(0) self.layout.setVerticalSpacing(0) self.layout.setContentsMargins(0, 0, 0, 0) # Setup ViewBox containing the colorbar self.vb = ViewBox() self.vb.setFixedWidth(10) self.vb.setLimits(xMin=0, xMax=1) self.vb.setMouseEnabled(x=False) self.vb.suggested_padding[1] = 0 # Setup colorbar, implemented as an ImageItem self.bar = pg.ImageItem() # The color bar ImageItem levels run from 0 to 1 self.bar.setImage(np.linspace(0, 1, 8192)[None, :]) self.vb.addItem(self.bar) self.layout.addItem(self.vb, 0, 0) # Setup axis self.axis = AxisItem(orientation='right') self.axis.linkToView(self.vb) self.axis.range_changed.connect(self.axis_to_levels) self.layout.addItem(self.axis, 0, 1) self.setLayout(self.layout) self.images = () self.images_min = {} self.images_max = {} self.manual_lut = None self.manual_levels = None self.setImages(images) if label is not None: self.setLabel(label)