def updateGraph(self): if self.data is None: return xInd, yInd, zInd = self.getAxesIndices() X, Y, Z, mask = self.getAxisData(xInd, yInd, zInd) if self.colorAttr > 0: colorAttr = self.axisCandidateAttrs[self.colorAttr - 1] C = self.dataArray[:, self.colorAttr - 1] if colorAttr.varType == orange.VarTypes.Discrete: palette = OWColorPalette.ColorPaletteHSV(len(colorAttr.values)) colors = [palette[int(value)] for value in C.ravel()] colors = [[c.red() / 255., c.green() / 255., c.blue() / 255.] for c in colors] else: palette = OWColorPalette.ColorPaletteBW() maxC, minC = numpy.max(C), numpy.min(C) C = (C - minC) / (maxC - minC) colors = [palette[value] for value in C.ravel()] colors = [[c.red() / 255., c.green() / 255., c.blue() / 255.] for c in colors] else: colors = "b" if self.sizeAttr > 0: sizeAttr = self.axisCandidateAttrs[self.sizeAttr - 1] S = self.dataArray[:, self.sizeAttr - 1] if sizeAttr.varType == orange.VarTypes.Discrete: sizes = [(v + 1) * len(sizeAttr.values) / (11 - self.pointSize) for v in S] else: min, max = numpy.min(S), numpy.max(S) sizes = [(v - min) * self.pointSize / (max - min) for v in S] else: sizes = 1 self.graph.clear() self.graph.scatter(X, Y, Z, colors, sizes)
def setExampleTable(self, data): self.colorCombo.clear() self.sizeCombo.clear() self.shapeCombo.clear() self.nameCombo.clear() attributes = list(data.domain.variables) + \ data.domain.getmetas().values() discAttributes = filter( lambda a: a.varType == orange.VarTypes.Discrete, attributes) contAttributes = filter( lambda a: a.varType == orange.VarTypes.Continuous, attributes) attrName = [attr.name for attr in attributes] for name in ["Same color"] + attrName: self.colorCombo.addItem(name) for name in ["Same size"] + map(lambda a: a.name, contAttributes): self.sizeCombo.addItem(name) for name in ["Same shape"] + map(lambda a: a.name, discAttributes): self.shapeCombo.addItem(name) for name in ["No name"] + attrName: self.nameCombo.addItem(name) try: self.graph.NameAttr = \ 1 + [name.lower() for name in attrName].index("name") except: pass self.attributes = attributes self.discAttributes = discAttributes self.contAttributes = contAttributes self.colors = [[Qt.black] * (len(attributes) + 1) for i in range(len(data))] self.shapes = [[QwtSymbol.Ellipse] * (len(discAttributes) + 1) for i in range(len(data))] self.sizes = [[5] * (len(contAttributes) + 1) for i in range(len(data))] self.names = [[""] * (len(attributes) + 1) for i in range(len(data))] try: selectedInput = self.selectedInputExamples.select(data.domain) except: selectedInput = [] self.selectedInput = map( lambda d: selectedInput and (d in selectedInput) or not selectedInput, data) contI = discI = attrI = 1 def check(ex, a): try: ex[a] except Exception: return False return not ex[a].isSpecial() for j, attr in enumerate(attributes): if attr.varType == orange.VarTypes.Discrete: c = OWColorPalette.ColorPaletteHSV(len(attr.values)) for i in range(len(data)): if check(data[i], attr): self.colors[i][attrI] = c[int(data[i][attr])] self.shapes[i][discI] = self.graph.shapeList[int( data[i][attr]) % len(self.graph.shapeList)] self.names[i][attrI] = " " + str(data[i][attr]) else: self.colors[i][attrI] = Qt.black self.shapes[i][discI] = self.graph.shapeList[0] self.names[i][attrI] = "" attrI += 1 discI += 1 elif attr.varType == orange.VarTypes.Continuous: c = OWColorPalette.ColorPaletteBW(-1) val = [e[attr] for e in data if check(e, attr)] minVal = min(val or [0]) maxVal = max(val or [1]) span = max(maxVal - minVal, 1e-6) for i in range(len(data)): if check(data[i], attr): self.colors[i][attrI] = c.getColor( (data[i][attr] - minVal) / span) self.names[i][attrI] = " " + str(data[i][attr]) self.sizes[i][contI] = int( self.data[i][attr] / maxVal * 9) + 1 else: self.colors[i][attrI] = Qt.black self.names[i][attrI] = "" self.sizes[i][contI] = 5 contI += 1 attrI += 1 else: for i in range(len(data)): self.colors[i][attrI] = Qt.black if check(data[i], attr): self.names[i][attrI] = " " + str(data[i][attr]) else: self.names[i][attrI] = "" attrI += 1 if data and data.domain.classVar: if data.domain.classVar.varType == orange.VarTypes.Discrete: self.graph.ColorAttr = len( self.colors[0]) - 1 # index 0 is Same color! elif data.domain.classVar.varType == orange.VarTypes.Continuous: self.graph.SizeAttr = len( self.sizes[0]) - 1 # index 0 is Same color!
def setExampleTable(self, data): self.colorCombo.clear() self.sizeCombo.clear() self.shapeCombo.clear() self.nameCombo.clear() attributes=[attr for attr in data.domain.variables+list(data.domain.getmetas().values()) or [] ] discAttributes=[a for a in attributes if a.varType==orange.VarTypes.Discrete] contAttributes=[a for a in attributes if a.varType==orange.VarTypes.Continuous] attrName=[attr.name for attr in attributes] for name in ["Same color"]+attrName: self.colorCombo.addItem(name) for name in ["Same size"]+[a.name for a in contAttributes]: self.sizeCombo.addItem(name) for name in ["Same shape"]+[a.name for a in discAttributes]: self.shapeCombo.addItem(name) for name in ["No name"]+attrName: self.nameCombo.addItem(name) # if data.domain.classVar: # if data.domain.classVar.varType == orange.VarTypes.Discrete: # self.graph.ColorAttr = len(data.domain.variables) # index 0 is Same color! # elif data.domain.classVar.varType == orange.VarTypes.Continuous: # self.graph.SizeAttr = len(data.domain.variables) # index 0 is Same color! try: self.graph.NameAttr = 1 + [name.lower() for name in attrName].index("name") except: pass self.attributes=attributes self.discAttributes=discAttributes self.contAttributes=contAttributes self.colors=[[Qt.black]*(len(attributes)+1) for i in range(len(data))] self.shapes=[[QwtSymbol.Ellipse]*(len(discAttributes)+1) for i in range(len(data))] self.sizes=[[5]*(len(contAttributes)+1) for i in range(len(data))] self.names=[[""]*(len(attributes)+1) for i in range(len(data))] try: selectedInput=self.selectedInputExamples.select(data.domain) except: selectedInput=[] self.selectedInput=[selectedInput and (d in selectedInput) or not selectedInput for d in data] contI=discI=attrI=1 def check(ex, a): try: ex[a] except: return False return not ex[a].isSpecial() for j, attr in enumerate(attributes): if attr.varType==orange.VarTypes.Discrete: c=OWColorPalette.ColorPaletteHSV(len(attr.values)) for i in range(len(data)): self.colors[i][attrI]= check(data[i],attr) and c[int(data[i][attr])] or Qt.black ## self.shapes[i][discI]= data[i][attr].isSpecial() and self.graph.shapeList[0] or self.graph.shapeList[int(data[i][attr])%len(self.graph.shapeList)] self.shapes[i][discI]= check(data[i],attr) and self.graph.shapeList[int(data[i][attr])%len(self.graph.shapeList)] or self.graph.shapeList[0] self.names[i][attrI]= check(data[i],attr) and " "+str(data[i][attr]) or "" #self.sizes[i][contI]=5 attrI+=1 discI+=1 elif attr.varType==orange.VarTypes.Continuous: c=OWColorPalette.ColorPaletteBW(-1) #val=[e[attr] for e in data if not e[attr].isSpecial()] val=[e[attr] for e in data if check(e, attr)] minVal=min(val or [0]) maxVal=max(val or [1]) for i in range(len(data)): self.colors[i][attrI]=check(data[i],attr) and c.getColor((data[i][attr]-minVal)/max(maxVal-minVal, 1e-6)) or Qt.black #self.shapes[i][discI]=self.graph.shapeList[0] self.names[i][attrI]=check(data[i],attr) and " "+str(data[i][attr]) or "" self.sizes[i][contI]=check(data[i],attr) and int(self.data[i][attr]/maxVal*9)+1 or 5 contI+=1 attrI+=1 else: for i in range(len(data)): self.colors[i][attrI]=Qt.black #self.shapes[i][j+1]=self.graph.shapeList[0] self.names[i][attrI]= check(data[i],attr) and " "+str(data[i][attr]) or "" #self.sizes[i][j+1]=5 attrI+=1 if data and data.domain.classVar: if data.domain.classVar.varType == orange.VarTypes.Discrete: self.graph.ColorAttr = len(self.colors[0]) - 1 # index 0 is Same color! elif data.domain.classVar.varType == orange.VarTypes.Continuous: self.graph.SizeAttr = len(self.sizes[0]) - 1 # index 0 is Same color!