def updateData(self, labels = None, setAnchors = 0, **args): self.removeDrawingCurves() # my function, that doesn't delete selection curves #self.removeCurves() self.removeMarkers() self.tooltipMarkers = [] self.__dict__.update(args) if labels == None: labels = [anchor[2] for anchor in self.anchorData] self.shownAttributes = labels self.dataMap = {} # dictionary with keys of form "x_i-y_i" with values (x_i, y_i, color, data) self.valueLineCurves = [{}, {}] # dicts for x and y set of coordinates for unconnected lines if not self.haveData or len(labels) < 3: self.anchorData = [] self.updateLayout() return if setAnchors or (args.has_key("XAnchors") and args.has_key("YAnchors")): self.potentialsBmp = None self.setAnchors(args.get("XAnchors"), args.get("YAnchors"), labels) #self.anchorData = self.createAnchors(len(labels), labels) # used for showing tooltips indices = [self.attributeNameIndex[anchor[2]] for anchor in self.anchorData] # store indices to shown attributes # do we want to show anchors and their labels if self.showAnchors: if self.hideRadius > 0: xdata = self.createXAnchors(100)*(self.hideRadius / 10) ydata = self.createYAnchors(100)*(self.hideRadius / 10) self.addCurve("hidecircle", QColor(200,200,200), QColor(200,200,200), 1, style = QwtPlotCurve.Lines, symbol = QwtSymbol.NoSymbol, xData = xdata.tolist() + [xdata[0]], yData = ydata.tolist() + [ydata[0]]) # draw dots at anchors shownAnchorData = filter(lambda p, r=self.hideRadius**2/100: p[0]**2+p[1]**2>r, self.anchorData) if not self.normalizeExamples: r=self.hideRadius**2/100 for i,(x,y,a) in enumerate(shownAnchorData): self.addCurve("l%i" % i, QColor(160, 160, 160), QColor(160, 160, 160), 10, style = QwtPlotCurve.Lines, symbol = QwtSymbol.NoSymbol, xData = [0, x], yData = [0, y], showFilledSymbols = 1, lineWidth=2) if self.showAttributeNames: self.addMarker(a, x*1.07, y*1.04, Qt.AlignCenter, bold=1) else: XAnchors = [a[0] for a in shownAnchorData] YAnchors = [a[1] for a in shownAnchorData] self.addCurve("dots", QColor(160,160,160), QColor(160,160,160), 10, style = QwtPlotCurve.NoCurve, symbol = QwtSymbol.Ellipse, xData = XAnchors, yData = YAnchors, showFilledSymbols = 1) # draw text at anchors if self.showAttributeNames: for x, y, a in shownAnchorData: self.addMarker(a, x*1.07, y*1.04, Qt.AlignCenter, bold = 1) if self.showAnchors and self.normalizeExamples: # draw "circle" xdata = self.createXAnchors(100) ydata = self.createYAnchors(100) self.addCurve("circle", QColor(Qt.black), QColor(Qt.black), 1, style = QwtPlotCurve.Lines, symbol = QwtSymbol.NoSymbol, xData = xdata.tolist() + [xdata[0]], yData = ydata.tolist() + [ydata[0]]) self.potentialsClassifier = None # remove the classifier so that repaint won't recompute it self.updateLayout() if self.dataHasDiscreteClass: self.discPalette.setNumberOfColors(len(self.dataDomain.classVar.values)) useDifferentSymbols = self.useDifferentSymbols and self.dataHasDiscreteClass and len(self.dataDomain.classVar.values) < len(self.curveSymbols) dataSize = len(self.rawData) validData = self.getValidList(indices) transProjData = self.createProjectionAsNumericArray(indices, validData = validData, scaleFactor = self.scaleFactor, normalize = self.normalizeExamples, jitterSize = -1, useAnchorData = 1, removeMissingData = 0) if transProjData == None: return projData = transProjData.T x_positions = projData[0] y_positions = projData[1] xPointsToAdd = {} yPointsToAdd = {} if self.showProbabilities and self.haveData and self.dataHasClass: # construct potentialsClassifier from unscaled positions domain = orange.Domain([self.dataDomain[i].name for i in indices]+[self.dataDomain.classVar.name], self.dataDomain) offsets = [self.attrValues[self.attributeNames[i]][0] for i in indices] normalizers = [self.getMinMaxVal(i) for i in indices] selectedData = numpy.take(self.originalData, indices, axis = 0) averages = numpy.average(numpy.compress(validData, selectedData, axis=1), 1) classData = numpy.compress(validData, self.originalData[self.dataClassIndex]) self.potentialsClassifier = orange.P2NN(domain, numpy.transpose(numpy.array([numpy.compress(validData, self.unscaled_x_positions), numpy.compress(validData, self.unscaled_y_positions), classData])), self.anchorData, offsets, normalizers, averages, self.normalizeExamples, law=1) # ############################################################## # show model quality # ############################################################## if self.insideColors != None or self.showKNN and self.haveData: # if we want to show knn classifications of the examples then turn the projection into example table and run knn if self.insideColors: insideData, stringData = self.insideColors else: shortData = self.createProjectionAsExampleTable([self.attributeNameIndex[attr] for attr in labels], useAnchorData = 1) predictions, probabilities = self.widget.vizrank.kNNClassifyData(shortData) if self.showKNN == 2: insideData, stringData = [1.0 - val for val in predictions], "Probability of wrong classification = %.2f%%" else: insideData, stringData = predictions, "Probability of correct classification = %.2f%%" if self.dataHasDiscreteClass: classColors = self.discPalette elif self.dataHasContinuousClass: classColors = self.contPalette if len(insideData) != len(self.rawData): j = 0 for i in range(len(self.rawData)): if not validData[i]: continue if self.dataHasClass: fillColor = classColors.getRGB(self.originalData[self.dataClassIndex][i], 255*insideData[j]) edgeColor = classColors.getRGB(self.originalData[self.dataClassIndex][i]) else: fillColor = edgeColor = (0,0,0) self.addCurve(str(i), QColor(*fillColor+ (self.alphaValue,)), QColor(*edgeColor+ (self.alphaValue,)), self.pointWidth, xData = [x_positions[i]], yData = [y_positions[i]]) if self.showValueLines: self.addValueLineCurve(x_positions[i], y_positions[i], edgeColor, i, indices) self.addTooltipKey(x_positions[i], y_positions[i], QColor(*edgeColor), i, stringData % (100*insideData[j])) j+= 1 else: for i in range(len(self.rawData)): if not validData[i]: continue if self.dataHasClass: fillColor = classColors.getRGB(self.originalData[self.dataClassIndex][i], 255*insideData[i]) edgeColor = classColors.getRGB(self.originalData[self.dataClassIndex][i]) else: fillColor = edgeColor = (0,0,0) self.addCurve(str(i), QColor(*fillColor+ (self.alphaValue,)), QColor(*edgeColor+ (self.alphaValue,)), self.pointWidth, xData = [x_positions[i]], yData = [y_positions[i]]) if self.showValueLines: self.addValueLineCurve(x_positions[i], y_positions[i], edgeColor, i, indices) self.addTooltipKey(x_positions[i], y_positions[i], QColor(*edgeColor), i, stringData % (100*insideData[i])) # ############################################################## # do we have a subset data to show? # ############################################################## elif self.haveSubsetData: shownSubsetCount = 0 subsetIdsToDraw = dict([(example.id,1) for example in self.rawSubsetData]) # draw the rawData data set. examples that exist also in the subset data draw full, other empty for i in range(dataSize): if not validData[i]: continue if subsetIdsToDraw.has_key(self.rawData[i].id): continue if self.dataHasDiscreteClass and self.useDifferentColors: newColor = self.discPalette.getRGB(self.originalData[self.dataClassIndex][i]) elif self.dataHasContinuousClass and self.useDifferentColors: newColor = self.contPalette.getRGB(self.noJitteringScaledData[self.dataClassIndex][i]) else: newColor = (0,0,0) if self.useDifferentSymbols and self.dataHasDiscreteClass: curveSymbol = self.curveSymbols[int(self.originalData[self.dataClassIndex][i])] else: curveSymbol = self.curveSymbols[0] if not xPointsToAdd.has_key((newColor, curveSymbol,0)): xPointsToAdd[(newColor, curveSymbol,0)] = [] yPointsToAdd[(newColor, curveSymbol,0)] = [] xPointsToAdd[(newColor, curveSymbol,0)].append(x_positions[i]) yPointsToAdd[(newColor, curveSymbol,0)].append(y_positions[i]) if self.showValueLines: self.addValueLineCurve(x_positions[i], y_positions[i], newColor, i, indices) self.addTooltipKey(x_positions[i], y_positions[i], QColor(*newColor), i) # if we have a data subset that contains examples that don't exist in the original dataset we show them here XAnchors = numpy.array([val[0] for val in self.anchorData]) YAnchors = numpy.array([val[1] for val in self.anchorData]) anchorRadius = numpy.sqrt(XAnchors*XAnchors + YAnchors*YAnchors) validSubData = self.getValidSubsetList(indices) projSubData = self.createProjectionAsNumericArray(indices, validData = validSubData, scaleFactor = self.scaleFactor, normalize = self.normalizeExamples, jitterSize = -1, useAnchorData = 1, removeMissingData = 0, useSubsetData = 1).T sub_x_positions = projSubData[0] sub_y_positions = projSubData[1] for i in range(len(self.rawSubsetData)): if not validSubData[i]: continue # check if has missing values if not self.dataHasClass or self.rawSubsetData[i].getclass().isSpecial(): newColor = (0,0,0) else: if self.dataHasDiscreteClass: newColor = self.discPalette.getRGB(self.originalSubsetData[self.dataClassIndex][i]) else: newColor = self.contPalette.getRGB(self.noJitteringScaledSubsetData[self.dataClassIndex][i]) if self.useDifferentSymbols and self.dataHasDiscreteClass and self.validSubsetDataArray[self.dataClassIndex][i]: curveSymbol = self.curveSymbols[int(self.originalSubsetData[self.dataClassIndex][i])] else: curveSymbol = self.curveSymbols[0] if not xPointsToAdd.has_key((newColor, curveSymbol, 1)): xPointsToAdd[(newColor, curveSymbol, 1)] = [] yPointsToAdd[(newColor, curveSymbol, 1)] = [] xPointsToAdd[(newColor, curveSymbol, 1)].append(sub_x_positions[i]) yPointsToAdd[(newColor, curveSymbol, 1)].append(sub_y_positions[i]) elif not self.dataHasClass: xs = []; ys = [] for i in range(dataSize): if not validData[i]: continue xs.append(x_positions[i]) ys.append(y_positions[i]) self.addTooltipKey(x_positions[i], y_positions[i], QColor(Qt.black), i) if self.showValueLines: self.addValueLineCurve(x_positions[i], y_positions[i], (0,0,0), i, indices) self.addCurve(str(1), QColor(0,0,0,self.alphaValue), QColor(0,0,0,self.alphaValue), self.pointWidth, symbol = self.curveSymbols[0], xData = xs, yData = ys, penAlpha = self.alphaValue, brushAlpha = self.alphaValue) # ############################################################## # CONTINUOUS class # ############################################################## elif self.dataHasContinuousClass: for i in range(dataSize): if not validData[i]: continue newColor = self.contPalette.getRGB(self.noJitteringScaledData[self.dataClassIndex][i]) self.addCurve(str(i), QColor(*newColor+ (self.alphaValue,)), QColor(*newColor+ (self.alphaValue,)), self.pointWidth, symbol = QwtSymbol.Ellipse, xData = [x_positions[i]], yData = [y_positions[i]]) if self.showValueLines: self.addValueLineCurve(x_positions[i], y_positions[i], newColor, i, indices) self.addTooltipKey(x_positions[i], y_positions[i], QColor(*newColor), i) # ############################################################## # DISCRETE class # ############################################################## elif self.dataHasDiscreteClass: for i in range(dataSize): if not validData[i]: continue if self.useDifferentColors: newColor = self.discPalette.getRGB(self.originalData[self.dataClassIndex][i]) else: newColor = (0,0,0) if self.useDifferentSymbols: curveSymbol = self.curveSymbols[int(self.originalData[self.dataClassIndex][i])] else: curveSymbol = self.curveSymbols[0] if not xPointsToAdd.has_key((newColor, curveSymbol, self.showFilledSymbols)): xPointsToAdd[(newColor, curveSymbol, self.showFilledSymbols)] = [] yPointsToAdd[(newColor, curveSymbol, self.showFilledSymbols)] = [] xPointsToAdd[(newColor, curveSymbol, self.showFilledSymbols)].append(x_positions[i]) yPointsToAdd[(newColor, curveSymbol, self.showFilledSymbols)].append(y_positions[i]) if self.showValueLines: self.addValueLineCurve(x_positions[i], y_positions[i], newColor, i, indices) self.addTooltipKey(x_positions[i], y_positions[i], QColor(*newColor), i) # first draw value lines if self.showValueLines: for i, color in enumerate(self.valueLineCurves[0].keys()): curve = UnconnectedLinesCurve("", QPen(QColor(*color + (self.alphaValue,))), self.valueLineCurves[0][color], self.valueLineCurves[1][color]) curve.attach(self) # draw all the points with a small number of curves for i, (color, symbol, showFilled) in enumerate(xPointsToAdd.keys()): xData = xPointsToAdd[(color, symbol, showFilled)] yData = yPointsToAdd[(color, symbol, showFilled)] self.addCurve(str(i), QColor(*color + (self.alphaValue,)), QColor(*color + (self.alphaValue,)), self.pointWidth, symbol = symbol, xData = xData, yData = yData, showFilledSymbols = showFilled) # ############################################################## # draw the legend # ############################################################## if self.showLegend: # show legend for discrete class if self.dataHasDiscreteClass: self.addMarker(self.dataDomain.classVar.name, 0.87, 1.05, Qt.AlignLeft | Qt.AlignVCenter) classVariableValues = getVariableValuesSorted(self.dataDomain.classVar) for index in range(len(classVariableValues)): if self.useDifferentColors: color = QColor(self.discPalette[index]) else: color = QColor(Qt.black) y = 1.0 - index * 0.05 if not self.useDifferentSymbols: curveSymbol = self.curveSymbols[0] else: curveSymbol = self.curveSymbols[index] self.addCurve(str(index), color, color, self.pointWidth, symbol = curveSymbol, xData = [0.95], yData = [y], penAlpha = self.alphaValue, brushAlpha = self.alphaValue) self.addMarker(classVariableValues[index], 0.90, y, Qt.AlignLeft | Qt.AlignVCenter) # show legend for continuous class elif self.dataHasContinuousClass: xs = [1.15, 1.20, 1.20, 1.15] count = 200 height = 2 / float(count) for i in range(count): y = -1.0 + i*2.0/float(count) col = self.contPalette[i/float(count)] col.setAlpha(self.alphaValue) PolygonCurve(QPen(col), QBrush(col), xData = xs, yData = [y,y, y+height, y+height]).attach(self) # add markers for min and max value of color attribute [minVal, maxVal] = self.attrValues[self.dataDomain.classVar.name] self.addMarker("%s = %%.%df" % (self.dataDomain.classVar.name, self.dataDomain.classVar.numberOfDecimals) % (minVal), xs[0] - 0.02, -1.0 + 0.04, Qt.AlignLeft) self.addMarker("%s = %%.%df" % (self.dataDomain.classVar.name, self.dataDomain.classVar.numberOfDecimals) % (maxVal), xs[0] - 0.02, +1.0 - 0.04, Qt.AlignLeft) self.replot()
def updateData(self, labels = None, setAnchors = 0, **args): self.removeDrawingCurves() # my function, that doesn't delete selection curves #self.removeCurves() self.removeMarkers() self.tooltipMarkers = [] self.__dict__.update(args) if labels == None: labels = [anchor[2] for anchor in self.anchorData] self.shownAttributes = labels self.dataMap = {} # dictionary with keys of form "x_i-y_i" with values (x_i, y_i, color, data) self.valueLineCurves = [{}, {}] # dicts for x and y set of coordinates for unconnected lines if not self.haveData or len(labels) < 3: self.anchorData = [] self.updateLayout() return if setAnchors or (args.has_key("XAnchors") and args.has_key("YAnchors")): self.potentialsBmp = None self.setAnchors(args.get("XAnchors"), args.get("YAnchors"), labels) #self.anchorData = self.createAnchors(len(labels), labels) # used for showing tooltips indices = [self.attributeNameIndex[anchor[2]] for anchor in self.anchorData] # store indices to shown attributes # do we want to show anchors and their labels if self.showAnchors: if self.hideRadius > 0: xdata = self.createXAnchors(100)*(self.hideRadius / 10) ydata = self.createYAnchors(100)*(self.hideRadius / 10) self.addCurve("hidecircle", QColor(200,200,200), QColor(200,200,200), 1, style = QwtPlotCurve.Lines, symbol = QwtSymbol.NoSymbol, xData = xdata.tolist() + [xdata[0]], yData = ydata.tolist() + [ydata[0]]) # draw dots at anchors shownAnchorData = filter(lambda p, r=self.hideRadius**2/100: p[0]**2+p[1]**2>r, self.anchorData) if not self.normalizeExamples: r=self.hideRadius**2/100 for i,(x,y,a) in enumerate(shownAnchorData): self.addCurve("l%i" % i, QColor(160, 160, 160), QColor(160, 160, 160), 10, style = QwtPlotCurve.Lines, symbol = QwtSymbol.NoSymbol, xData = [0, x], yData = [0, y], showFilledSymbols = 1, lineWidth=2) if self.showAttributeNames: self.addMarker(a, x*1.07, y*1.04, Qt.AlignCenter, bold=1) else: XAnchors = [a[0] for a in shownAnchorData] YAnchors = [a[1] for a in shownAnchorData] self.addCurve("dots", QColor(160,160,160), QColor(160,160,160), 10, style = QwtPlotCurve.NoCurve, symbol = QwtSymbol.Ellipse, xData = XAnchors, yData = YAnchors, showFilledSymbols = 1) # draw text at anchors if self.showAttributeNames: for x, y, a in shownAnchorData: self.addMarker(a, x*1.07, y*1.04, Qt.AlignCenter, bold = 1) if self.showAnchors and self.normalizeExamples: # draw "circle" xdata = self.createXAnchors(100) ydata = self.createYAnchors(100) self.addCurve("circle", QColor(Qt.black), QColor(Qt.black), 1, style = QwtPlotCurve.Lines, symbol = QwtSymbol.NoSymbol, xData = xdata.tolist() + [xdata[0]], yData = ydata.tolist() + [ydata[0]]) self.potentialsClassifier = None # remove the classifier so that repaint won't recompute it self.updateLayout() if self.dataHasDiscreteClass: self.discPalette.setNumberOfColors(len(self.dataDomain.classVar.values)) useDifferentSymbols = self.useDifferentSymbols and self.dataHasDiscreteClass and len(self.dataDomain.classVar.values) < len(self.curveSymbols) dataSize = len(self.rawData) validData = self.getValidList(indices) # jitter point if Radviz transProjData = self.createProjectionAsNumericArray(indices, validData = validData, scaleFactor = self.scaleFactor, normalize = self.normalizeExamples, jitterSize = self.jitter_size if self.normalizeExamples else -1, useAnchorData = 1, removeMissingData = 0) if transProjData == None: return projData = transProjData.T x_positions = projData[0] y_positions = projData[1] xPointsToAdd = {} yPointsToAdd = {} if self.showProbabilities and self.haveData and self.dataHasClass: # construct potentialsClassifier from unscaled positions domain = orange.Domain([self.dataDomain[i].name for i in indices]+[self.dataDomain.classVar.name], self.dataDomain) offsets = [self.attrValues[self.attributeNames[i]][0] for i in indices] normalizers = [self.getMinMaxVal(i) for i in indices] selectedData = numpy.take(self.originalData, indices, axis = 0) averages = numpy.average(numpy.compress(validData, selectedData, axis=1), 1) classData = numpy.compress(validData, self.originalData[self.dataClassIndex]) if classData.any(): self.potentialsClassifier = orange.P2NN(domain, numpy.transpose(numpy.array([numpy.compress(validData, self.unscaled_x_positions), numpy.compress(validData, self.unscaled_y_positions), classData])), self.anchorData, offsets, normalizers, averages, self.normalizeExamples, law=1) else: self.potentialsClassifier = None self.potentialsImage = None # ############################################################## # show model quality # ############################################################## if self.insideColors != None or self.showKNN and self.haveData: # if we want to show knn classifications of the examples then turn the projection into example table and run knn if self.insideColors: insideData, stringData = self.insideColors else: shortData = self.createProjectionAsExampleTable([self.attributeNameIndex[attr] for attr in labels], useAnchorData = 1) predictions, probabilities = self.widget.vizrank.kNNClassifyData(shortData) if self.showKNN == 2: insideData, stringData = [1.0 - val for val in predictions], "Probability of wrong classification = %.2f%%" else: insideData, stringData = predictions, "Probability of correct classification = %.2f%%" if self.dataHasDiscreteClass: classColors = self.discPalette elif self.dataHasContinuousClass: classColors = self.contPalette if len(insideData) != len(self.rawData): j = 0 for i in range(len(self.rawData)): if not validData[i]: continue if self.dataHasClass: fillColor = classColors.getRGB(self.originalData[self.dataClassIndex][i], 255*insideData[j]) edgeColor = classColors.getRGB(self.originalData[self.dataClassIndex][i]) else: fillColor = edgeColor = (0,0,0) self.addCurve(str(i), QColor(*fillColor+ (self.alphaValue,)), QColor(*edgeColor+ (self.alphaValue,)), self.pointWidth, xData = [x_positions[i]], yData = [y_positions[i]]) if self.showValueLines: self.addValueLineCurve(x_positions[i], y_positions[i], edgeColor, i, indices) self.addTooltipKey(x_positions[i], y_positions[i], QColor(*edgeColor), i, stringData % (100*insideData[j])) j+= 1 else: for i in range(len(self.rawData)): if not validData[i]: continue if self.dataHasClass: fillColor = classColors.getRGB(self.originalData[self.dataClassIndex][i], 255*insideData[i]) edgeColor = classColors.getRGB(self.originalData[self.dataClassIndex][i]) else: fillColor = edgeColor = (0,0,0) self.addCurve(str(i), QColor(*fillColor+ (self.alphaValue,)), QColor(*edgeColor+ (self.alphaValue,)), self.pointWidth, xData = [x_positions[i]], yData = [y_positions[i]]) if self.showValueLines: self.addValueLineCurve(x_positions[i], y_positions[i], edgeColor, i, indices) self.addTooltipKey(x_positions[i], y_positions[i], QColor(*edgeColor), i, stringData % (100*insideData[i])) # ############################################################## # do we have a subset data to show? # ############################################################## elif self.haveSubsetData: shownSubsetCount = 0 subsetIdsToDraw = dict([(example.id,1) for example in self.rawSubsetData]) subsetIdsAlreadyDrawn = set() # draw the rawData data set. examples that exist also in the subset data draw full, other empty for i in range(dataSize): if not validData[i]: continue if subsetIdsToDraw.has_key(self.rawData[i].id): instance_filled = 1 subsetIdsAlreadyDrawn.add(self.rawData[i].id) else: instance_filled = 0 if self.dataHasDiscreteClass and self.useDifferentColors: newColor = self.discPalette.getRGB(self.originalData[self.dataClassIndex][i]) elif self.dataHasContinuousClass and self.useDifferentColors: newColor = self.contPalette.getRGB(self.noJitteringScaledData[self.dataClassIndex][i]) else: newColor = (0,0,0) if self.useDifferentSymbols and self.dataHasDiscreteClass: curveSymbol = self.curveSymbols[int(self.originalData[self.dataClassIndex][i])] else: curveSymbol = self.curveSymbols[0] if not xPointsToAdd.has_key((newColor, curveSymbol, instance_filled)): xPointsToAdd[(newColor, curveSymbol, instance_filled)] = [] yPointsToAdd[(newColor, curveSymbol, instance_filled)] = [] xPointsToAdd[(newColor, curveSymbol, instance_filled)].append(x_positions[i]) yPointsToAdd[(newColor, curveSymbol, instance_filled)].append(y_positions[i]) if self.showValueLines: self.addValueLineCurve(x_positions[i], y_positions[i], newColor, i, indices) self.addTooltipKey(x_positions[i], y_positions[i], QColor(*newColor), i) # if we have a data subset that contains examples that don't exist in the original dataset we show them here XAnchors = numpy.array([val[0] for val in self.anchorData]) YAnchors = numpy.array([val[1] for val in self.anchorData]) anchorRadius = numpy.sqrt(XAnchors*XAnchors + YAnchors*YAnchors) validSubData = self.getValidSubsetList(indices) # jitter points if Radviz projSubData = self.createProjectionAsNumericArray(indices, validData = validSubData, scaleFactor = self.scaleFactor, normalize = self.normalizeExamples, jitterSize = self.jitter_size if self.normalizeExamples else -1, useAnchorData = 1, removeMissingData = 0, useSubsetData = 1).T sub_x_positions = projSubData[0] sub_y_positions = projSubData[1] for i in range(len(self.rawSubsetData)): if not validSubData[i]: # check if has missing values continue if self.rawSubsetData[i].id in subsetIdsAlreadyDrawn: continue if not self.dataHasClass or self.rawSubsetData[i].getclass().isSpecial(): newColor = (0,0,0) else: if self.dataHasDiscreteClass: newColor = self.discPalette.getRGB(self.originalSubsetData[self.dataClassIndex][i]) else: newColor = self.contPalette.getRGB(self.noJitteringScaledSubsetData[self.dataClassIndex][i]) if self.useDifferentSymbols and self.dataHasDiscreteClass and self.validSubsetDataArray[self.dataClassIndex][i]: curveSymbol = self.curveSymbols[int(self.originalSubsetData[self.dataClassIndex][i])] else: curveSymbol = self.curveSymbols[0] if not xPointsToAdd.has_key((newColor, curveSymbol, 1)): xPointsToAdd[(newColor, curveSymbol, 1)] = [] yPointsToAdd[(newColor, curveSymbol, 1)] = [] xPointsToAdd[(newColor, curveSymbol, 1)].append(sub_x_positions[i]) yPointsToAdd[(newColor, curveSymbol, 1)].append(sub_y_positions[i]) elif not self.dataHasClass: xs = []; ys = [] for i in range(dataSize): if not validData[i]: continue xs.append(x_positions[i]) ys.append(y_positions[i]) self.addTooltipKey(x_positions[i], y_positions[i], QColor(Qt.black), i) if self.showValueLines: self.addValueLineCurve(x_positions[i], y_positions[i], (0,0,0), i, indices) self.addCurve(str(1), QColor(0,0,0,self.alphaValue), QColor(0,0,0,self.alphaValue), self.pointWidth, symbol = self.curveSymbols[0], xData = xs, yData = ys, penAlpha = self.alphaValue, brushAlpha = self.alphaValue) # ############################################################## # CONTINUOUS class # ############################################################## elif self.dataHasContinuousClass: for i in range(dataSize): if not validData[i]: continue newColor = self.contPalette.getRGB(self.noJitteringScaledData[self.dataClassIndex][i]) self.addCurve(str(i), QColor(*newColor+ (self.alphaValue,)), QColor(*newColor+ (self.alphaValue,)), self.pointWidth, symbol = QwtSymbol.Ellipse, xData = [x_positions[i]], yData = [y_positions[i]]) if self.showValueLines: self.addValueLineCurve(x_positions[i], y_positions[i], newColor, i, indices) self.addTooltipKey(x_positions[i], y_positions[i], QColor(*newColor), i) # ############################################################## # DISCRETE class # ############################################################## elif self.dataHasDiscreteClass: for i in range(dataSize): if not validData[i]: continue if self.useDifferentColors: newColor = self.discPalette.getRGB(self.originalData[self.dataClassIndex][i]) else: newColor = (0,0,0) if self.useDifferentSymbols: curveSymbol = self.curveSymbols[int(self.originalData[self.dataClassIndex][i])] else: curveSymbol = self.curveSymbols[0] if not xPointsToAdd.has_key((newColor, curveSymbol, self.showFilledSymbols)): xPointsToAdd[(newColor, curveSymbol, self.showFilledSymbols)] = [] yPointsToAdd[(newColor, curveSymbol, self.showFilledSymbols)] = [] xPointsToAdd[(newColor, curveSymbol, self.showFilledSymbols)].append(x_positions[i]) yPointsToAdd[(newColor, curveSymbol, self.showFilledSymbols)].append(y_positions[i]) if self.showValueLines: self.addValueLineCurve(x_positions[i], y_positions[i], newColor, i, indices) self.addTooltipKey(x_positions[i], y_positions[i], QColor(*newColor), i) # first draw value lines if self.showValueLines: for i, color in enumerate(self.valueLineCurves[0].keys()): curve = UnconnectedLinesCurve("", QPen(QColor(*color + (self.alphaValue,))), self.valueLineCurves[0][color], self.valueLineCurves[1][color]) curve.attach(self) # draw all the points with a small number of curves for i, (color, symbol, showFilled) in enumerate(xPointsToAdd.keys()): xData = xPointsToAdd[(color, symbol, showFilled)] yData = yPointsToAdd[(color, symbol, showFilled)] self.addCurve(str(i), QColor(*color + (self.alphaValue,)), QColor(*color + (self.alphaValue,)), self.pointWidth, symbol = symbol, xData = xData, yData = yData, showFilledSymbols = showFilled) # ############################################################## # draw the legend # ############################################################## if self.showLegend: # show legend for discrete class if self.dataHasDiscreteClass: self.addMarker(self.dataDomain.classVar.name, 0.87, 1.05, Qt.AlignLeft | Qt.AlignVCenter) classVariableValues = getVariableValuesSorted(self.dataDomain.classVar) for index in range(len(classVariableValues)): if self.useDifferentColors: color = QColor(self.discPalette[index]) else: color = QColor(Qt.black) y = 1.0 - index * 0.05 if not self.useDifferentSymbols: curveSymbol = self.curveSymbols[0] else: curveSymbol = self.curveSymbols[index] self.addCurve(str(index), color, color, self.pointWidth, symbol = curveSymbol, xData = [0.95], yData = [y], penAlpha = self.alphaValue, brushAlpha = self.alphaValue) self.addMarker(classVariableValues[index], 0.90, y, Qt.AlignLeft | Qt.AlignVCenter) # show legend for continuous class elif self.dataHasContinuousClass: xs = [1.15, 1.20, 1.20, 1.15] count = 200 height = 2 / float(count) for i in range(count): y = -1.0 + i*2.0/float(count) col = self.contPalette[i/float(count)] col.setAlpha(self.alphaValue) PolygonCurve(QPen(col), QBrush(col), xData = xs, yData = [y,y, y+height, y+height]).attach(self) # add markers for min and max value of color attribute [minVal, maxVal] = self.attrValues[self.dataDomain.classVar.name] self.addMarker("%s = %%.%df" % (self.dataDomain.classVar.name, self.dataDomain.classVar.numberOfDecimals) % (minVal), xs[0] - 0.02, -1.0 + 0.04, Qt.AlignLeft) self.addMarker("%s = %%.%df" % (self.dataDomain.classVar.name, self.dataDomain.classVar.numberOfDecimals) % (maxVal), xs[0] - 0.02, +1.0 - 0.04, Qt.AlignLeft) self.replot()
def showAnchorLines(self): for i, color in enumerate(self.xLinesToAdd.keys()): curve = UnconnectedLinesCurve("", QPen(QColor(*color)), self.xLinesToAdd[color], self.yLinesToAdd[color]) curve.attach(self)