Changeset 47:8c29813f5150 in orange


Ignore:
Timestamp:
04/02/03 09:30:38 (10 years ago)
Author:
tomazc <tomazc@…>
Branch:
default
Convert:
71d91b367ef04c48fe012c9fa763f36954af6cea
Message:

krivulja verjetnosti zdaj nad vsemi "bar"-i (ce le-teh manj kot 10007, glej OWGraph.py)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/OWDistributions.py

    r32 r47  
    2020from OWGraph import * 
    2121 
    22 class subBarQwtCurve(QwtCurve): 
     22class subBarQwtPlotCurve(QwtPlotCurve): 
    2323    def __init__(self, parent = None, text = None): 
    24         QwtCurve.__init__(self, parent, text) 
     24        QwtPlotCurve.__init__(self, parent, text) 
    2525        self.color = Qt.black 
    2626 
     
    3838            px2 = xMap.transform(self.x(i+1)) 
    3939            py2 = yMap.transform(self.y(i+1)) 
    40 #            print "draw from ", px1, ",", py1, "to", px2, ",", py2 
    4140            p.drawRect(px1, py1, (px2 - px1), (py2 - py1)) 
    4241 
    43 class subBarQwtPlotCurve(QwtPlotCurve, subBarQwtCurve): # there must be a better way to do this 
    44     def dummy(): 
    45         None 
     42class errorBarQwtPlotCurve(QwtPlotCurve): 
     43    def __init__(self, parent = None, text = None): 
     44        QwtPlotCurve.__init__(self, parent, text) 
     45 
     46    def draw(self, p, xMap, yMap, f, t): 
     47        self.setPen( self.symbol().pen() ) 
     48        p.setPen( self.symbol().pen() ) 
     49        if self.style() == QwtCurve.UserCurve: 
     50            p.setBackgroundMode(Qt.OpaqueMode) 
     51            if t < 0: t = self.dataSize() - 1 
     52            if divmod(f, 3)[1] != 0: f -= f % 3 
     53            if divmod(t, 3)[1] == 0:  t += 1 
     54            for i in range(f, t+1, 3): 
     55                px = xMap.transform(self.x(i)) 
     56                pxl = xMap.transform(self.x(i) - 0.1) 
     57                pxr = xMap.transform(self.x(i) + 0.1) 
     58                py1 = yMap.transform(self.y(i + 0)) 
     59                py2 = yMap.transform(self.y(i + 1)) 
     60                py3 = yMap.transform(self.y(i + 2)) 
     61                p.drawLine(px, py1, px, py3) 
     62                p.drawLine(pxl, py1, pxr, py1) 
     63                p.drawLine(pxl, py3, pxr, py3) 
     64                self.symbol().draw(p, px, py2) 
     65        else: 
     66            QwtPlotCurve.draw(self, p, xMap, yMap, f, t) 
     67 
    4668 
    4769class OWDistributions(OWWidget): 
     
    91113        self.outcomenames = [] 
    92114        self.probGraphValues = [] 
    93         self.probCurveKey = self.graph.insertCurve('', QwtPlot.xBottom, QwtPlot.yRight) 
     115 
     116        curve = errorBarQwtPlotCurve(self.graph, '') 
     117        self.probCurveKey = self.graph.insertCurve(curve) 
     118        self.graph.setCurveXAxis(self.probCurveKey, QwtPlot.xBottom) 
     119        self.graph.setCurveYAxis(self.probCurveKey, QwtPlot.yRight) 
     120 
    94121        self.probCurveUpperCIKey = self.graph.insertCurve('', QwtPlot.xBottom, QwtPlot.yRight) 
    95122        self.probCurveLowerCIKey = self.graph.insertCurve('', QwtPlot.xBottom, QwtPlot.yRight) 
     
    308335 
    309336        self.graph.removeCurves() 
    310 ##        newColor = QColor() 
    311 ##        newColor.setHsv(5*360/12, 255, 255) 
    312 ##        curve = subBarQwtPlotCurve(self.graph) 
    313 ##        curve.setPen(QPen(newColor)) 
    314 ##        ckey = self.graph.insertCurve(curve) 
    315 ##        self.graph.setCurveStyle(ckey, QwtCurve.UserCurve) 
    316 ##        self.graph.setCurveData(ckey, [10, 11], [5, 7]) 
    317337 
    318338        currentBarsHeight = [0] * len(keys) 
     
    337357                    currentBarsHeight[cn] += subBarHeight 
    338358                    cn += 1 
    339         self.probCurveKey = self.graph.insertCurve('', QwtPlot.xBottom, QwtPlot.yRight) 
     359 
     360        curve = errorBarQwtPlotCurve(self.graph, '') 
     361        self.probCurveKey = self.graph.insertCurve(curve) 
     362        self.graph.setCurveXAxis(self.probCurveKey, QwtPlot.xBottom) 
     363        self.graph.setCurveYAxis(self.probCurveKey, QwtPlot.yRight) 
     364 
    340365        self.probCurveUpperCIKey = self.graph.insertCurve('', QwtPlot.xBottom, QwtPlot.yRight) 
    341366        self.probCurveLowerCIKey = self.graph.insertCurve('', QwtPlot.xBottom, QwtPlot.yRight) 
     
    344369    def refreshProbGraph(self): 
    345370        if self.ShowProbabilities: 
    346             if self.VariableContinuous: 
    347                 newSymbol = QwtSymbol() 
    348             else: 
    349                 newSymbol = QwtSymbol() #QwtSymbol.Cross, QBrush(Qt.red), QPen(Qt.red), QSize(1,100)) 
    350  
    351371            self.graph.enableYRaxis(1) 
    352372            xs = [] 
     
    358378                if self.VariableContinuous: 
    359379                    xs.append(x) 
     380                    ups.append(ps[self.targetValue] + cis[self.targetValue]) 
     381                    mps.append(ps[self.targetValue] + 0.0) 
     382                    lps.append(ps[self.targetValue] - cis[self.targetValue]) 
    360383                else: 
     384                    if self.ShowConfidenceIntervals: 
     385                        xs.append(cn) 
     386                        mps.append(ps[self.targetValue] + cis[self.targetValue]) 
     387 
    361388                    xs.append(cn) 
    362                 ups.append(ps[self.targetValue] + cis[self.targetValue]) 
    363                 mps.append(ps[self.targetValue] + 0.0) 
    364                 lps.append(ps[self.targetValue] - cis[self.targetValue]) 
     389                    mps.append(ps[self.targetValue] + 0.0) 
     390 
     391                    if self.ShowConfidenceIntervals: 
     392                        xs.append(cn) 
     393                        mps.append(ps[self.targetValue] - cis[self.targetValue]) 
    365394                cn += 1.0 
     395 
     396            ## (re)set the curves 
     397            if self.VariableContinuous: 
     398                newSymbol = QwtSymbol(QwtSymbol.None, QBrush(Qt.color0), QPen(Qt.black, 2), QSize(0,0)) 
     399            else: 
     400                newSymbol = QwtSymbol(QwtSymbol.Diamond, QBrush(Qt.color0), QPen(Qt.black, 2), QSize(7,7)) 
    366401 
    367402            self.graph.setCurveData(self.probCurveKey, xs, mps) 
    368403            self.graph.setCurveSymbol(self.probCurveKey, newSymbol) 
    369             if self.ShowConfidenceIntervals: 
    370                 self.graph.setCurveData(self.probCurveUpperCIKey, xs, ups) 
    371                 self.graph.setCurveData(self.probCurveLowerCIKey, xs, lps) 
     404 
     405            if self.VariableContinuous: 
     406                self.graph.setCurveStyle(self.probCurveKey, QwtCurve.Lines) 
     407                if self.ShowConfidenceIntervals: 
     408                    self.graph.setCurveData(self.probCurveUpperCIKey, xs, ups) 
     409                    self.graph.setCurveData(self.probCurveLowerCIKey, xs, lps) 
     410            else: 
     411                if self.ShowConfidenceIntervals: 
     412                    self.graph.setCurveStyle(self.probCurveKey, QwtCurve.UserCurve) 
     413                else: 
     414                    self.graph.setCurveStyle(self.probCurveKey, QwtCurve.Dots) 
    372415        else: 
    373416            self.graph.enableYRaxis(0) 
Note: See TracChangeset for help on using the changeset viewer.