def _column1(): if role == Qt.DecorationRole: continuous_palette = ContinuousPaletteGenerator(*var.colors) line = continuous_palette.getRGB(np.arange(0, 1, 1 / 256)) data = np.arange(0, 256, dtype=np.int8).reshape( (1, 256)).repeat(16, 0) img = QImage(data, 256, 16, QImage.Format_Indexed8) img.setColorCount(256) img.setColorTable([qRgb(*x) for x in line]) img.data = data return img if role == Qt.ToolTipRole: return "{} - {}".format(self._encode_color(var.colors[0]), self._encode_color(var.colors[1])) if role == ColorRole: return var.colors
def _column1(): if role == Qt.DecorationRole: continuous_palette = ContinuousPaletteGenerator(*var.colors) line = continuous_palette.getRGB(np.arange(0, 1, 1 / 256)) data = np.arange(0, 256, dtype=np.int8). \ reshape((1, 256)). \ repeat(16, 0) img = QImage(data, 256, 16, QImage.Format_Indexed8) img.setColorCount(256) img.setColorTable([qRgb(*x) for x in line]) img.data = data return img if role == Qt.ToolTipRole: return "{} - {}".format(self._encode_color(var.colors[0]), self._encode_color(var.colors[1])) if role == ColorRole: return var.colors
def _column1(): if role == Qt.DecorationRole: continuous_palette = \ ContinuousPaletteGenerator(*desc.get_colors()) line = continuous_palette.getRGB(np.arange(0, 1, 1 / 256)) data = np.arange(0, 256, dtype=np.int8). \ reshape((1, 256)). \ repeat(16, 0) img = QImage(data, 256, 16, QImage.Format_Indexed8) img.setColorCount(256) img.setColorTable([qRgb(*x) for x in line]) img.data = data return img if role == Qt.ToolTipRole: colors = desc.get_colors() return f"{self._encode_color(colors[0])} " \ f"- {self._encode_color(colors[1])}" if role == ColorRole: return desc.get_colors() return None
class ProbabilitiesItem(orangeqt.PlotItem): """ Displays class probabilities in the background :param classifier: The classifier for which the probabilities are calculated :type classifier: orange.P2NN :param granularity: The size of individual cells :type granularity: int :param scale: The data scale factor :type scale: float :param spacing: The space between cells :param spacing: int :param rect: The rectangle into which to draw the probabilities. If unspecified, the entire plot is used. :type rect: QRectF """ def __init__(self, classifier, granularity, scale, spacing, rect=None): orangeqt.PlotItem.__init__(self) self.classifier = classifier self.rect = rect self.granularity = granularity self.scale = scale self.spacing = spacing self.pixmap_item = QGraphicsPixmapItem(self) self.set_in_background(True) self.setZValue(ProbabilitiesZValue) def update_properties(self): ## Mostly copied from OWScatterPlotGraph if not self.plot(): return if not self.rect: x,y = self.axes() self.rect = self.plot().data_rect_for_axes(x,y) s = self.graph_transform().mapRect(self.rect).size().toSize() if not s.isValid(): return rx = s.width() ry = s.height() rx -= rx % self.granularity ry -= ry % self.granularity p = self.graph_transform().map(QPointF(0, 0)) - self.graph_transform().map(self.rect.topLeft()) p = p.toPoint() ox = p.x() oy = -p.y() if self.classifier.classVar.is_continuous: imagebmp = orangeom.potentialsBitmap(self.classifier, rx, ry, ox, oy, self.granularity, self.scale) palette = [qRgb(255.*i/255., 255.*i/255., 255-(255.*i/255.)) for i in range(255)] + [qRgb(255, 255, 255)] else: imagebmp, nShades = orangeom.potentialsBitmap(self.classifier, rx, ry, ox, oy, self.granularity, self.scale, self.spacing) palette = [] sortedClasses = get_variable_values_sorted(self.classifier.domain.classVar) for cls in self.classifier.classVar.values: color = self.plot().discPalette.getRGB(sortedClasses.index(cls)) towhite = [255-c for c in color] for s in range(nShades): si = 1-float(s)/nShades palette.append(qRgb(*tuple([color[i]+towhite[i]*si for i in (0, 1, 2)]))) palette.extend([qRgb(255, 255, 255) for i in range(256-len(palette))]) self.potentialsImage = QImage(imagebmp, rx, ry, QImage.Format_Indexed8) self.potentialsImage.setColorTable(palette) self.potentialsImage.setNumColors(256) self.pixmap_item.setPixmap(QPixmap.fromImage(self.potentialsImage)) self.pixmap_item.setPos(self.graph_transform().map(self.rect.bottomLeft())) def data_rect(self): return self.rect if self.rect else QRectF()