def _update_color(self):
        if self.plotdata is None:
            return

        colorvar = self._color_var()
        validmask = self.plotdata.validmask
        selectionmask = self.plotdata.selectionmask
        if colorvar is not None:
            colors = plotutils.color_data(self.data, colorvar)[validmask]
        else:
            colors = numpy.array([[192, 192, 192]])
            colors = numpy.tile(colors, (self.plotdata.X.shape[0], 1))

        selectedmask = selectionmask[validmask]
        pointstyle = numpy.where(
            selectedmask, plotutils.Selected, plotutils.NoFlags)

        pendata = plotutils.pen_data(colors * 0.8, pointstyle)
        colors = numpy.hstack(
            [colors, numpy.full((colors.shape[0], 1), float(self.opacity))])

        brushdata = plotutils.brush_data(colors, )
        if self.plotdata.subsetmask is not None:
            subsetmask = self.plotdata.subsetmask[validmask]
            brushdata[~subsetmask] = QtGui.QBrush(Qt.NoBrush)

        self.plotdata.pendata = pendata
        self.plotdata.brushdata = brushdata
        self.plotdata.mainitem.setPen(pendata)
        self.plotdata.mainitem.setBrush(brushdata)

        self._update_legend()
Пример #2
0
    def _update_color(self):
        if self.plotdata is None:
            return

        colorvar = self._color_var()
        validmask = self.plotdata.validmask
        selectionmask = self.plotdata.selectionmask
        if colorvar is not None:
            colors = plotutils.color_data(self.data, colorvar)[validmask]
        else:
            colors = numpy.array([[192, 192, 192]])
            colors = numpy.tile(colors, (self.plotdata.X.shape[0], 1))

        selectedmask = selectionmask[validmask]
        pointstyle = numpy.where(
            selectedmask, plotutils.Selected, plotutils.NoFlags)

        pendata = plotutils.pen_data(colors * 0.8, pointstyle)
        colors = numpy.hstack(
            [colors, numpy.full((colors.shape[0], 1), float(self.opacity))])
        brushdata = plotutils.brush_data(colors)

        self.plotdata.pendata = pendata
        self.plotdata.brushdata = brushdata
        self.plotdata.mainitem.setPen(pendata)
        self.plotdata.mainitem.setBrush(brushdata)

        self._update_legend()
Пример #3
0
    def _update_density(self):
        if self.plotdata is None:
            return

        if self.plotdata.densityimage is not None:
            self.plot.removeItem(self.plotdata.densityimage)
            self.plotdata.densityimage = None

        if self.data.domain.has_discrete_class and self.class_density:
            coords = self.plotdata.embedding_coords
            radius = numpy.linalg.norm(coords, axis=1).max()
            coords = coords / radius
            xmin = ymin = -1.05
            xmax = ymax = 1.05
            xdata, ydata = coords.T
            colors = plotutils.color_data(self.data, self.data.domain.class_var)[self.plotdata.validmask]
            imgitem = classdensity.class_density_image(xmin, xmax, ymin, ymax, 256, xdata, ydata, colors)
            self.plot.addItem(imgitem)
            self.plotdata.densityimage = imgitem
    def _update_density(self):
        if self.plotdata is None:
            return

        if self.plotdata.densityimage is not None:
            self.plot.removeItem(self.plotdata.densityimage)
            self.plotdata.densityimage = None

        if self.data.domain.has_discrete_class and self.class_density:
            coords = self.plotdata.embedding_coords
            radius = numpy.linalg.norm(coords, axis=1).max()
            coords = coords / radius
            xmin = ymin = -1.05
            xmax = ymax = 1.05
            xdata, ydata = coords.T
            colors = plotutils.color_data(
                self.data, self.data.domain.class_var)[self.plotdata.validmask]
            imgitem = classdensity.class_density_image(
                xmin, xmax, ymin, ymax, 256, xdata, ydata, colors)
            self.plot.addItem(imgitem)
            self.plotdata.densityimage = imgitem
    def _setup(self):
        """
        Setup the plot.
        """
        X = self.data.X
        Y = self.data.Y
        mask = numpy.bitwise_or.reduce(numpy.isnan(X), axis=1)
        mask |= numpy.isnan(Y)
        valid = ~mask
        X = X[valid, :]
        Y = Y[valid]

        if self.data.domain.class_var.is_discrete:
            Y = Y.astype(int)
        X = (X - numpy.mean(X, axis=0))
        span = numpy.ptp(X, axis=0)
        X[:, span > 0] /= span[span > 0].reshape(1, -1)

        if self.initialization == OWFreeViz.Circular:
            anchors = linproj.linproj.defaultaxes(X.shape[1]).T
        else:
            anchors = numpy.random.random((X.shape[1], 2)) * 2 - 1

        EX = numpy.dot(X, anchors)
        radius = numpy.max(numpy.linalg.norm(EX, axis=1))

        jittervec = numpy.random.RandomState(4).rand(*EX.shape) * 2 - 1
        jittervec *= 0.01
        _, jitterfactor = self.JitterAmount[self.jitter]

        colorvar = self._color_var()
        shapevar = self._shape_var()
        sizevar = self._size_var()
        labelvar = self._label_var()

        if colorvar is not None:
            colors = plotutils.color_data(self.data, colorvar)[valid]
        else:
            colors = numpy.array([[192, 192, 192]])
            colors = numpy.tile(colors, (X.shape[0], 1))

        pendata = plotutils.pen_data(colors * 0.8)
        colors = numpy.hstack(
            [colors, numpy.full((colors.shape[0], 1), float(self.opacity))])
        brushdata = plotutils.brush_data(colors)

        shapedata = plotutils.shape_data(self.data, shapevar)[valid]
        sizedata = size_data(
            self.data, sizevar, pointsize=self.point_size)[valid]
        if labelvar is not None:
            labeldata = plotutils.column_data(self.data, labelvar, valid)
            labeldata = [labelvar.str_val(val) for val in labeldata]
        else:
            labeldata = None

        coords = (EX / radius) + jittervec * jitterfactor
        item = linproj.ScatterPlotItem(
            x=coords[:, 0],
            y=coords[:, 1],
            brush=brushdata,
            pen=pendata,
            symbols=shapedata,
            size=sizedata,
            data=numpy.flatnonzero(valid),
            antialias=True,
        )

        self.plot.addItem(item)
        self.plot.setRange(QtCore.QRectF(-1.05, -1.05, 2.1, 2.1))

        # minimum visible anchor radius
        minradius = self.min_anchor_radius / 100 + 1e-5
        axisitems = []
        for anchor, var in zip(anchors, self.data.domain.attributes):
            axitem = AxisItem(
                line=QtCore.QLineF(0, 0, *anchor), label=var.name,)
            axitem.setVisible(numpy.linalg.norm(anchor) > minradius)
            axitem.setPen(pg.mkPen((100, 100, 100)))
            axitem.setArrowVisible(False)
            self.plot.addItem(axitem)
            axisitems.append(axitem)

        hidecircle = QtGui.QGraphicsEllipseItem()
        hidecircle.setRect(
            QtCore.QRectF(-minradius, -minradius,
                          2 * minradius, 2 * minradius))

        _pen = QtGui.QPen(Qt.lightGray, 1)
        _pen.setCosmetic(True)
        hidecircle.setPen(_pen)

        self.plot.addItem(hidecircle)

        self.plotdata = namespace(
            validmask=valid,
            embedding_coords=EX,
            jittervec=jittervec,
            anchors=anchors,
            mainitem=item,
            axisitems=axisitems,
            hidecircle=hidecircle,
            basecolors=colors,
            brushdata=brushdata,
            pendata=pendata,
            shapedata=shapedata,
            sizedata=sizedata,
            labeldata=labeldata,
            labelitems=[],
            densityimage=None,
            X=X,
            Y=Y,
            selectionmask=numpy.zeros_like(valid, dtype=bool),
            subsetmask=None
        )
        self._update_legend()
        self._update_labels()
        self._update_density()
Пример #6
0
    def _setup(self):
        """
        Setup the plot.
        """
        X = self.data.X
        Y = self.data.Y
        mask = numpy.bitwise_or.reduce(numpy.isnan(X), axis=1)
        mask |= numpy.isnan(Y)
        valid = ~mask
        X = X[valid, :]
        Y = Y[valid]

        if self.data.domain.class_var.is_discrete:
            Y = Y.astype(int)
        X = (X - numpy.mean(X, axis=0))
        span = numpy.ptp(X, axis=0)
        X[:, span > 0] /= span[span > 0].reshape(1, -1)

        if self.initialization == OWFreeViz.Circular:
            anchors = linproj.linproj.defaultaxes(X.shape[1]).T
        else:
            anchors = numpy.random.random((X.shape[1], 2)) * 2 - 1

        EX = numpy.dot(X, anchors)
        radius = numpy.max(numpy.linalg.norm(EX, axis=1))

        jittervec = numpy.random.RandomState(4).rand(*EX.shape) * 2 - 1
        jittervec *= 0.01
        _, jitterfactor = self.JitterAmount[self.jitter]

        colorvar = self._color_var()
        shapevar = self._shape_var()
        sizevar = self._size_var()
        labelvar = self._label_var()

        if colorvar is not None:
            colors = plotutils.color_data(self.data, colorvar)[valid]
        else:
            colors = numpy.array([[192, 192, 192]])
            colors = numpy.tile(colors, (X.shape[0], 1))

        pendata = plotutils.pen_data(colors * 0.8)
        colors = numpy.hstack(
            [colors, numpy.full((colors.shape[0], 1), float(self.opacity))])
        brushdata = plotutils.brush_data(colors)

        shapedata = plotutils.shape_data(self.data, shapevar)[valid]
        sizedata = size_data(
            self.data, sizevar, pointsize=self.point_size)[valid]
        if labelvar is not None:
            labeldata = plotutils.column_data(self.data, labelvar, valid)
            labeldata = [labelvar.str_val(val) for val in labeldata]
        else:
            labeldata = None

        coords = (EX / radius) + jittervec * jitterfactor
        item = linproj.ScatterPlotItem(
            x=coords[:, 0],
            y=coords[:, 1],
            brush=brushdata,
            pen=pendata,
            symbols=shapedata,
            size=sizedata,
            data=numpy.flatnonzero(valid),
            antialias=True,
        )

        self.plot.addItem(item)
        self.plot.setRange(QtCore.QRectF(-1.05, -1.05, 2.1, 2.1))

        # minimum visible anchor radius
        minradius = self.min_anchor_radius / 100 + 1e-5
        axisitems = []
        for anchor, var in zip(anchors, self.data.domain.attributes):
            axitem = AxisItem(
                line=QtCore.QLineF(0, 0, *anchor), label=var.name,)
            axitem.setVisible(numpy.linalg.norm(anchor) > minradius)
            axitem.setPen(pg.mkPen((100, 100, 100)))
            axitem.setArrowVisible(False)
            self.plot.addItem(axitem)
            axisitems.append(axitem)

        hidecircle = QtGui.QGraphicsEllipseItem()
        hidecircle.setRect(
            QtCore.QRectF(-minradius, -minradius,
                          2 * minradius, 2 * minradius))

        _pen = QtGui.QPen(Qt.lightGray, 1)
        _pen.setCosmetic(True)
        hidecircle.setPen(_pen)

        self.plot.addItem(hidecircle)

        self.plotdata = namespace(
            validmask=valid,
            embedding_coords=EX,
            jittervec=jittervec,
            anchors=anchors,
            mainitem=item,
            axisitems=axisitems,
            hidecircle=hidecircle,
            basecolors=colors,
            brushdata=brushdata,
            pendata=pendata,
            shapedata=shapedata,
            sizedata=sizedata,
            labeldata=labeldata,
            labelitems=[],
            densityimage=None,
            X=X,
            Y=Y,
            selectionmask=numpy.zeros_like(valid, dtype=bool)
        )
        self._update_legend()
        self._update_labels()
        self._update_density()