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

📄 owscatterplotmatrix.py

📁 orange源码 数据挖掘技术
💻 PY
📖 第 1 页 / 共 2 页
字号:
"""
<name>Scatterplot matrix</name>
<description>Scatterplot matrix visualization.</description>
<contact>Gregor Leban (gregor.leban@fri.uni-lj.si)</contact>
<icon>icons/ScatterPlotMatrix.png</icon>
<priority>1100</priority>
"""
# ScatterPlotMatrix.py
#
# Show data using scatterplot matrix visualization method
# 

from OWWidget import *
from OWScatterPlotGraph import OWScatterPlotGraph
#import qt
import orngInteract
import statc
import OWDlgs, OWGUI
from math import sqrt

class QMyLabel(QLabel):
    def __init__(self, size, *args):
        apply(QLabel.__init__,(self,) + args)
        self.size = size

    def setSize(self, size):
        self.size = size
 
    def sizeHint(self):
        return self.size

###########################################################################################
##### WIDGET : Parallel coordinates visualization
###########################################################################################
class OWScatterPlotMatrix(OWWidget):
    settingsList = ["pointWidth", "showAxisScale", "showXaxisTitle", "showYLaxisTitle",  "showLegend", "jitterSize", "jitterContinuous", "showFilledSymbols", "colorSettings"]
    jitterSizeNums = [0.1,   0.5,  1,  2,  5,  10, 15, 20]
    
    def __init__(self,parent=None, signalManager = None):
        OWWidget.__init__(self, parent, signalManager, "Scatterplot matrix", TRUE)

        self.inputs = [("Classified Examples", ExampleTableWithClass, self.cdata), ("Selection", list, self.selection)]
        self.outputs = [("Attribute selection", list)] 

        #set default settings
        self.data = None
        
        self.pointWidth = 5
        self.showAxisScale = 1
        self.showXaxisTitle = 0
        self.showYLaxisTitle = 0
        self.showLegend = 0
        self.jitterContinuous = 0
        self.jitterSize = 2
        self.showFilledSymbols = 1
        self.shownAttrCount = 0
        self.graphCanvasColor = str(Qt.white.name())
        self.attributeSelection = None
        self.colorSettings = None

        #load settings
        self.loadSettings()

        #GUI
        self.tabs = QTabWidget(self.space, 'tabWidget')
        self.GeneralTab = QVGroupBox(self)
        self.SettingsTab = QVGroupBox(self, "Settings")
        self.tabs.insertTab(self.GeneralTab, "General")
        self.tabs.insertTab(self.SettingsTab, "Settings")
        
        #add controls to self.controlArea widget
        self.shownAttribsGroup = OWGUI.widgetBox(self.GeneralTab, " Shown Attributes " )
        self.shownAttribsGroup.setMinimumWidth(200)
        hbox = OWGUI.widgetBox(self.shownAttribsGroup, orientation = 'horizontal')
        self.addRemoveGroup = OWGUI.widgetBox(self.GeneralTab, 1, orientation = "horizontal" )
        self.hiddenAttribsGroup = OWGUI.widgetBox(self.GeneralTab, " Hidden Attributes ")

        self.shownAttribsLB = QListBox(hbox)
        self.shownAttribsLB.setSelectionMode(QListBox.Extended)

        self.hiddenAttribsLB = QListBox(self.hiddenAttribsGroup)
        self.hiddenAttribsLB.setSelectionMode(QListBox.Extended)

        vbox = OWGUI.widgetBox(hbox, orientation = 'vertical')
        self.buttonUPAttr   = OWGUI.button(vbox, self, "", callback = self.moveAttrUP, tooltip="Move selected attributes up")
        self.buttonDOWNAttr = OWGUI.button(vbox, self, "", callback = self.moveAttrDOWN, tooltip="Move selected attributes down")
        self.buttonUPAttr.setPixmap(QPixmap(os.path.join(self.widgetDir, r"icons\Dlg_up1.png")))
        self.buttonUPAttr.setSizePolicy(QSizePolicy(QSizePolicy.Fixed , QSizePolicy.Expanding))
        self.buttonUPAttr.setMaximumWidth(20)
        self.buttonDOWNAttr.setPixmap(QPixmap(os.path.join(self.widgetDir, r"icons\Dlg_down1.png")))
        self.buttonDOWNAttr.setSizePolicy(QSizePolicy(QSizePolicy.Fixed , QSizePolicy.Expanding))
        self.buttonDOWNAttr.setMaximumWidth(20)
        self.buttonUPAttr.setMaximumWidth(20)

        self.attrAddButton =    OWGUI.button(self.addRemoveGroup, self, "", callback = self.addAttribute, tooltip="Add (show) selected attributes")
        self.attrAddButton.setPixmap(QPixmap(os.path.join(self.widgetDir, r"icons\Dlg_up2.png")))
        self.attrRemoveButton = OWGUI.button(self.addRemoveGroup, self, "", callback = self.removeAttribute, tooltip="Remove (hide) selected attributes")
        self.attrRemoveButton.setPixmap(QPixmap(os.path.join(self.widgetDir, r"icons\Dlg_down2.png")))

        self.createMatrixButton = OWGUI.button(self.GeneralTab, self, "Create matrix", callback = self.createGraphs, tooltip="Create scatterplot matrix using shown attributes")

        # ####################################
        # settings tab
        OWGUI.hSlider(self.SettingsTab, self, 'pointWidth', box=' Point Size ', minValue=1, maxValue=20, step=1, callback = self.setPointWidth)

        box2 = OWGUI.widgetBox(self.SettingsTab, " Jittering Options ")
        box3 = OWGUI.widgetBox(box2, orientation = "horizontal")
        self.jitterLabel = QLabel('Jittering size (% of size)  ', box3)
        self.jitterSizeCombo = OWGUI.comboBox(box3, self, "jitterSize", callback = self.updateJitteringSettings, items = self.jitterSizeNums, sendSelectedValue = 1, valueType = float)
        OWGUI.checkBox(box2, self, 'jitterContinuous', 'Jitter continuous attributes', callback = self.updateJitteringSettings, tooltip = "Does jittering apply also on continuous attributes?")

        box4 = OWGUI.widgetBox(self.SettingsTab, " General Graph Settings ")
        OWGUI.checkBox(box4, self, 'showAxisScale', 'Show axis scale', callback = self.updateSettings)
        OWGUI.checkBox(box4, self, 'showXaxisTitle', 'X axis title', callback = self.updateSettings)
        OWGUI.checkBox(box4, self, 'showYLaxisTitle', 'Y axis title', callback = self.updateSettings)
        OWGUI.checkBox(box4, self, 'showLegend', 'Show legend', callback = self.updateSettings)
        OWGUI.checkBox(box4, self, 'showFilledSymbols', 'Show filled symbols', callback = self.updateSettings)
        
        hbox = OWGUI.widgetBox(self.SettingsTab, "Colors", orientation = "horizontal")
        OWGUI.button(hbox, self, "Set Colors", self.setColors, tooltip = "Set the canvas background color and color palette for coloring continuous variables", debuggingEnabled = 0)

        self.connect(self.graphButton, SIGNAL("clicked()"), self.saveToFile)

        self.grid = QGridLayout(self.mainArea)
        self.graphs = []
        self.labels = []
        self.graphParameters = []

        # add a settings dialog and initialize its values
        self.icons = self.createAttributeIconDict()    
        self.activateLoadedSettings()
        self.resize(900, 700)
        

    # #########################
    # OPTIONS
    # #########################
    def activateLoadedSettings(self):
        dlg = self.createColorDialog()
        self.contPalette = dlg.getContinuousPalette("contPalette")
        self.discPalette = dlg.getDiscretePalette()
        self.graphCanvasColor = dlg.getColor("Canvas")
        
    def createColorDialog(self):
        c = OWDlgs.ColorPalette(self, "Color Palette")
        c.createDiscretePalette(" Discrete Palette ")
        c.createContinuousPalette("contPalette", " Continuous palette ")
        box = c.createBox("otherColors", " Other Colors ")
        c.createColorButton(box, "Canvas", "Canvas color", Qt.white)
        box.addSpace(5)
        box.adjustSize()
        c.setColorSchemas(self.colorSettings)
        return c

    def setColors(self):
        dlg = self.createColorDialog()
        if dlg.exec_loop():
            self.colorSettings = dlg.getColorSchemas()
            self.contPalette = dlg.getContinuousPalette("contPalette")
            self.discPalette = dlg.getDiscretePalette()
            self.graphCanvasColor = dlg.getColor("Canvas")
            self.updateSettings()
            
    def setGraphOptions(self, graph, title):
        graph.showAxisScale = self.showAxisScale
        graph.showXaxisTitle = self.showXaxisTitle
        graph.showYLaxisTitle = self.showYLaxisTitle
        graph.showLegend = self.showLegend
        graph.showFilledSymbols = self.showFilledSymbols
        graph.setCanvasBackground(self.graphCanvasColor)
        graph.contPalette = self.contPalette
        graph.discPalette = self.discPalette


    def setPointWidth(self):
        for graph in self.graphs:
            graph.pointWidth = n
        self.updateGraph()
        
    def updateShowLegend(self):
        for graph in self.graphs:
            graph.showLegend = self.showLegend

    def updateJitteringSettings(self):
        if self.graphs == []: return
        self.graphs[0].jitterSize = self.jitterSize
        self.graphs[0].jitterContinuous = self.jitterContinuous
        self.graphs[0].setData(self.data)
        
        for graph in self.graphs[1:]:
            graph.jitterSize = self.jitterSize
            graph.jitterContinuous = self.jitterContinuous
            graph.scaledData = self.graphs[0].scaledData
            graph.validDataArray = self.graphs[0].validDataArray
            graph.attributeNameIndex = self.graphs[0].attributeNameIndex
            graph.domainDataStat = self.graphs[0].domainDataStat
            graph.attributeNames = self.graphs[0].attributeNames
        self.updateGraph()
    
    # #########################
    # GRAPH MANIPULATION
    # #########################
    def updateSettings(self):
        for i in range(len(self.graphs)):
            (attr1, attr2, className, title) = self.graphParameters[i]
            self.setGraphOptions(self.graphs[i], title)
        self.updateGraph()
    
    def updateGraph(self):
        for i in range(len(self.graphs)):
            (attr1, attr2, className, title) = self.graphParameters[i]
            self.graphs[i].updateData(attr1, attr2, className)
            self.graphs[i].repaint()
            
    def removeAllGraphs(self):
        for graph in self.graphs:
            graph.hide()
            graph.destroy()
        self.graphs = []
        self.graphParameters = []

        for label in self.labels:
            label.hide()
        self.labels = []
    

    def createGraphs(self):
        self.removeAllGraphs()

        list = []
        for i in range(self.shownAttribsLB.count()): list.append(str(self.shownAttribsLB.text(i)))
        list.reverse()
        count = len(list)

⌨️ 快捷键说明

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