⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 owscatterplotgraph.py

📁 orange源码 数据挖掘技术
💻 PY
📖 第 1 页 / 共 3 页
字号:
                    try: distribution = contXY[str(xValues[i])+'-'+str(yValues[j])]
                    except: continue
                    tempSum = 0
                    for val in distribution: tempSum += val
                    if tempSum == 0: continue

                    tooltipText = "Nr. of examples: <b>%d</b> (%.2f%%) <br>Distribution:" % (tempSum, 100.0*float(tempSum)/float(sum))
                    out = [0.0]
                    key = self.addCurve(QwtPlotCurvePieChart(self), QColor(), QColor(), 0, style = QwtCurve.UserCurve, symbol = QwtSymbol.None)
                    for classVal in classValuesSorted:
                        val = classValues.index(classVal)
                        out += [out[-1] + float(distribution[val])/float(tempSum)]
                        tooltipText += "<br>%s : <b>%d</b> (%.2f%%)" % (classVal, distribution[val], 100.0*distribution[val]/float(tempSum))
                    self.setCurveData(key, [i, j] + [0]*(len(out)-2), out)
                    self.curve(key).percentOfTotalData = float(tempSum) / float(sum)
                    self.tooltipData.append((tooltipText, i, j))
            self.addTooltips()

        # ##############################################################
        # show normal scatterplot with dots
        else:
            if self.insideColors and self.rawdata.domain.classVar and self.rawdata.domain.classVar.varType == orange.VarTypes.Discrete:
                # variables and domain for the table
                classValueIndices = getVariableValueIndices(self.rawdata, self.rawdata.domain.classVar.name)
                (insideData, stringData) = self.insideColors
                j = 0
                equalSize = len(self.rawdata) == len(insideData)
                for i in range(len(self.rawdata)):
                    if not validData[i]:
                        j += equalSize
                        continue
                    
                    fillColor = self.discPalette[classValueIndices[self.rawdata[i].getclass().value], 255*insideData[j]]
                    edgeColor = self.discPalette[classValueIndices[self.rawdata[i].getclass().value]]

                    x = xData[i]
                    y = yData[i]
                    key = self.addCurve(str(i), fillColor, edgeColor, self.pointWidth, xData = [x], yData = [y])

                    # we add a tooltip for this point
                    self.addTip(x, y, text = self.getExampleTooltipText(self.rawdata, self.rawdata[j], attrIndices))
                    j+=1
                    
            # ##############################################################
            # create a small number of curves which will make drawing much faster
            # ##############################################################
            elif self.optimizedDrawing and (colorIndex == -1 or self.rawdata.domain[colorIndex].varType == orange.VarTypes.Discrete) and shapeIndex == -1 and sizeShapeIndex == -1 and not haveSubsetData:
                if colorIndex != -1:
                    classCount = len(colorIndices)
                else: classCount = 1

                pos = [[ [] , [], [] ] for i in range(classCount)]
                indices = [colorIndex, xAttrIndex, yAttrIndex]
                if -1 in indices: indices.remove(-1)
                validData = self.getValidList(indices)
                for i in range(len(self.rawdata)):
                    if not validData[i]: continue
                    x = xData[i]
                    y = yData[i]

                    if colorIndex != -1: index = colorIndices[self.rawdata[i][colorIndex].value]
                    else:                index = 0
                    pos[index][0].append(x)
                    pos[index][1].append(y)
                    pos[index][2].append(i)

                    # we add a tooltip for this point
                    self.tips.addToolTip(x, y, i)

                    # Show a label by each marker
                    if labelAttr:
                        all_accessible = [self.rawdata.domain.getmeta(mykey) for mykey in self.rawdata.domain.getmetas().keys()] + [var for var in self.rawdata.domain.attributes]
                        if self.rawdata.domain.classVar:
                            all_accessible.append(self.rawdata.domain.classVar)
                        metanames = [myvar.name for myvar in all_accessible ]
                        if labelAttr in metanames:
                            if self.rawdata.domain.classVar and labelAttr==self.rawdata.domain.classVar.name:
                                lbl = str(self.rawdata.domain.classVar.values[int(self.rawdata[i][labelAttr])])
                            else:
                                if self.rawdata[i][labelAttr].varType==orange.VarTypes.Continuous and not self.rawdata[i][labelAttr].isSpecial():
                                    lbl = "%4.1f" % orange.Value(self.rawdata[i][labelAttr])
                                else:
                                    lbl = str(orange.Value(self.rawdata[i][labelAttr]))
                            mkey = self.insertMarker(lbl)
                            self.marker(mkey).setXValue(float(x))
                            self.marker(mkey).setYValue(float(y))
                            self.marker(mkey).setLabelAlignment(Qt.AlignCenter + Qt.AlignBottom)
                     

                for i in range(classCount):
                    if colorIndex != -1: newColor = self.discPalette[i]
                    else:                newColor = QColor(0,0,0)
                    key = self.addCurve(str(i), newColor, newColor, self.pointWidth, symbol = self.curveSymbols[0], xData = pos[i][0], yData = pos[i][1])
                

            # ##############################################################
            # slow, unoptimized drawing because we use different symbols and/or different sizes of symbols
            # ##############################################################
            else:
                shownSubsetCount = 0
                attrs = [xAttrIndex, yAttrIndex, colorIndex, shapeIndex, sizeShapeIndex]
                while -1 in attrs: attrs.remove(-1)
                validData = self.getValidList(attrs)
                if self.subsetData:
                    subsetReferencesToDraw = [example.reference() for example in self.subsetData]
                showFilled = self.showFilledSymbols
                
                for i in range(len(self.rawdata)):
                    if not validData[i]: continue
                    x = xData[i]
                    y = yData[i]
                    
                    if colorIndex != -1:
                        if self.rawdata.domain[colorIndex].varType == orange.VarTypes.Continuous:
                            newColor = self.contPalette[self.noJitteringScaledData[colorIndex][i]]
                        else:
                            newColor = self.discPalette[colorIndices[self.rawdata[i][colorIndex].value]]
                    else: newColor = QColor(0,0,0)
                            
                    Symbol = self.curveSymbols[0]
                    if shapeIndex != -1: Symbol = self.curveSymbols[shapeIndices[self.rawdata[i][shapeIndex].value]]

                    size = self.pointWidth
                    if sizeShapeIndex != -1: size = MIN_SHAPE_SIZE + round(self.noJitteringScaledData[sizeShapeIndex][i] * self.pointWidth)
                    
                    if haveSubsetData:
                        showFilled = self.rawdata[i].reference() in subsetReferencesToDraw
                        shownSubsetCount += showFilled

                    self.addCurve(str(i), newColor, newColor, size, symbol = Symbol, xData = [x], yData = [y], showFilledSymbols = showFilled)
                        
                    # we add a tooltip for this point
                    self.tips.addToolTip(x, y, i)

                # if we have a data subset that contains examples that don't exist in the original dataset we show them here
                if haveSubsetData and shownSubsetCount < len(self.subsetData):
                    for i in range(len(self.subsetData)):
                        if not self.subsetData[i].reference() in subsetReferencesToDraw: continue
                        if self.subsetData[i][xAttrIndex].isSpecial() or self.subsetData[i][yAttrIndex].isSpecial() : continue
                        if colorIndex != -1 and self.subsetData[i][colorIndex].isSpecial() : continue
                        if shapeIndex != -1 and self.subsetData[i][shapeIndex].isSpecial() : continue
                        if sizeShapeIndex != -1 and self.subsetData[i][sizeShapeIndex].isSpecial() : continue
                        
                        if discreteX == 1: x = attrXIndices[self.subsetData[i][xAttrIndex].value] + self.rndCorrection(float(self.jitterSize) / 100.0)
                        elif self.jitterContinuous:     x = self.subsetData[i][xAttrIndex].value + self.rndCorrection(float(self.jitterSize*xVar) / 100.0)
                        else:                           x = self.subsetData[i][xAttrIndex].value

                        if discreteY == 1: y = attrYIndices[self.subsetData[i][yAttrIndex].value] + self.rndCorrection(float(self.jitterSize) / 100.0)
                        elif self.jitterContinuous:     y = self.subsetData[i][yAttrIndex].value + self.rndCorrection(float(self.jitterSize*yVar) / 100.0)
                        else:                           y = self.subsetData[i][yAttrIndex].value

                        if colorIndex != -1 and not self.subsetData[i][colorIndex].isSpecial():
                            val = min(1.0, max(0.0, self.scaleExampleValue(self.subsetData[i], colorIndex)))    # scale to 0-1 interval
                            if self.rawdata.domain[colorIndex].varType == orange.VarTypes.Continuous:
                                newColor = self.contPalette[val]
                            else:
                                newColor = self.discPalette[colorIndices[self.subsetData[i][colorIndex].value]]
                        else: newColor = QColor(0,0,0)
                                
                        Symbol = self.curveSymbols[0]
                        if shapeIndex != -1: Symbol = self.curveSymbols[shapeIndices[self.subsetData[i][shapeIndex].value]]

                        size = self.pointWidth
                        if sizeShapeIndex != -1: size = MIN_SHAPE_SIZE + round(self.noJitteringScaledData[sizeShapeIndex][i] * self.pointWidth)
                        self.addCurve(str(i), newColor, newColor, size, symbol = Symbol, xData = [x], yData = [y], showFilledSymbols = 1)

        
        # ##############################################################
        # show legend if necessary
        if self.showLegend == 1:
            legendKeys = {}
            if colorIndex != -1 and self.rawdata.domain[colorIndex].varType == orange.VarTypes.Discrete:
                num = len(self.rawdata.domain[colorIndex].values)
                val = [[], [], [self.pointWidth]*num, [QwtSymbol.Ellipse]*num]
                varValues = getVariableValuesSorted(self.rawdata, colorIndex)
                for ind in range(num):
                    val[0].append(self.rawdata.domain[colorIndex].name + "=" + varValues[ind])
                    val[1].append(self.discPalette[ind])
                legendKeys[colorIndex] = val

            if shapeIndex != -1 and self.rawdata.domain[shapeIndex].varType == orange.VarTypes.Discrete:
                num = len(self.rawdata.domain[shapeIndex].values)
                if legendKeys.has_key(shapeIndex):  val = legendKeys[shapeIndex]
                else:                               val = [[], [QColor(0,0,0)]*num, [self.pointWidth]*num, []]
                varValues = getVariableValuesSorted(self.rawdata, shapeIndex)
                val[3] = []; val[0] = []
                for ind in range(num):
                    val[3].append(self.curveSymbols[ind])
                    val[0].append(self.rawdata.domain[shapeIndex].name + "=" + varValues[ind])
                legendKeys[shapeIndex] = val

            if sizeShapeIndex != -1 and self.rawdata.domain[sizeShapeIndex].varType == orange.VarTypes.Discrete:
                num = len(self.rawdata.domain[sizeShapeIndex ].values)
                if legendKeys.has_key(sizeShapeIndex):  val = legendKeys[sizeShapeIndex]
                else:                               val = [[], [QColor(0,0,0)]*num, [], [QwtSymbol.Ellipse]*num]
                val[2] = []; val[0] = []
                varValues = getVariableValuesSorted(self.rawdata, sizeShapeIndex)
                for ind in range(num):
                    val[0].append(self.rawdata.domain[sizeShapeIndex].name + "=" + varValues[ind])
                    val[2].append(MIN_SHAPE_SIZE + round(ind*self.pointWidth/len(varValues)))
                legendKeys[sizeShapeIndex] = val
        else:
            legendKeys = {}

        if legendKeys != self.oldLegendKeys:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -