Пример #1
0
 def createPalette(self, color1, color2, passThroughBlack, colorNumber=250):
     if passThroughBlack:
         palette = [
             qRgb(color1.red() - color1.red() * i * 2. / colorNumber,
                  color1.green() - color1.green() * i * 2. / colorNumber,
                  color1.blue() - color1.blue() * i * 2. / colorNumber)
             for i in range(colorNumber / 2)
         ]
         palette += [
             qRgb(color2.red() * i * 2. / colorNumber,
                  color2.green() * i * 2. / colorNumber,
                  color2.blue() * i * 2. / colorNumber)
             for i in range(colorNumber - (colorNumber / 2))
         ]
     else:
         palette = [
             qRgb(
                 color1.red() +
                 (color2.red() - color1.red()) * i / colorNumber,
                 color1.green() +
                 (color2.green() - color1.green()) * i / colorNumber,
                 color1.blue() +
                 (color2.blue() - color1.blue()) * i / colorNumber)
             for i in range(colorNumber)
         ]
     return palette
Пример #2
0
 def createPalette(self, color1, color2, passThroughBlack, colorNumber=250):
     if passThroughBlack:
         palette = [qRgb(color1.red() - color1.red() * i * 2. / colorNumber,
                         color1.green() - color1.green() * i * 2. / colorNumber,
                         color1.blue() - color1.blue() * i * 2. / colorNumber) for i in range(colorNumber / 2)]
         palette += [qRgb(color2.red() * i * 2. / colorNumber, color2.green() * i * 2. / colorNumber,
                          color2.blue() * i * 2. / colorNumber) for i in range(colorNumber - (colorNumber / 2))]
     else:
         palette = [qRgb(color1.red() + (color2.red() - color1.red()) * i / colorNumber,
                         color1.green() + (color2.green() - color1.green()) * i / colorNumber,
                         color1.blue() + (color2.blue() - color1.blue()) * i / colorNumber) for i in
                    range(colorNumber)]
     return palette
Пример #3
0
    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()))
Пример #4
0
 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
Пример #5
0
 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
Пример #6
0
 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