Esempio n. 1
0
 def _drawHorizontalGridLine(self):
     # calculate xmin and xmax points for lines to completely cross graph
     hgridx = [
         distr.distrppf(self.activeProbit, 0.0001) - 1,
         distr.distrppf(self.activeProbit, 0.9999) + 1
     ]
     # calculate log scale for lines y values
     self.hgridy = self._logrange(10**self.axisY.min(),
                                  10**self.axisY.max(),
                                  base=10)
     self.hgridseries = []
     # create a line series for each lines and add to list
     for val in self.hgridy:
         line = '%d' % val
         tdict = {'X': hgridx, line: [log10(val)] * 2}
         self.hgridseries = self.hgridseries + XLineSeries(
             tdict, xkey='X', openGL=True)
     # add each of the series to the grid with special formatting
     for i, line in enumerate(self.hgridseries):
         pen = line.pen()
         pen.setColor(self.gridcolor)
         pen.setWidthF(0.4), line.setPen(pen)
         self.addSeries(line)
         self.setAxes(line)
         self.legend().markers(line)[0].setVisible(False)
Esempio n. 2
0
    def addLinearReg(self, seriesname):
        x = self.data[seriesname]['X'], y = self.data[seriesname][seriesname]
        # adds a linear regression line for a data set x,y
        slope, intercept, r_value, p_value, std_err = linregress(x, y)
        xmin = distr.distrppf(self.activeDistr, 0.01)
        xmax = distr.distrppf(self.activeDistr, 0.99)
        ymin = slope * xmin + intercept
        ymax = slope * xmax + intercept
        data = dict()
        data['X'] = [xmin, xmax]
        data['LinearReg'] = [ymin, ymax]
        lines = XLineSeries(data, xkey='X', openGL=True)

        self.addSeries(lines[0])
        self.setAxes(lines[0])
Esempio n. 3
0
    def resetAxes(self):
        ymins = []
        ymaxs = []
        for key in self.data.keys():
            ymins.append(min(self.data[key]))
            ymaxs.append(max(self.data[key]))
        try:
            ymin = min(ymins)
            ymax = max(ymaxs)
        except ValueError:
            ymin = 1.1
            ymax = 2

        xmin = distr.distrppf(self.activeProbit, 0.001)
        xmax = distr.distrppf(self.activeProbit, 0.999)
        if self.activeScale == 'linear':
            yscal = 0.1 * (ymax - ymin)
            self.setAxesMinMax(xmin, xmax, ymin - yscal, ymax + yscal)
        elif self.activeScale == 'log10':
            yscal = 0.1 * (log10(ymax) - log10(ymin))
            self.setAxesMinMax(xmin, xmax, log10(ymin), log10(ymax))
Esempio n. 4
0
 def plotSeries(self, name):
     nsamp = len(self.data[name])
     # add data to temport dictionary
     tdict = dict()
     if self.activeScale == 'log10':
         tdict[name] = log10(self.data[name])
     elif self.activeScale == 'linear':
         tdict[name] = self.data[name]
     tdict['X'] = distr.distrppf(self.activeProbit, [
         percentileofscore(self.data[name], self.data[name][i]) / 100.00001
         for i in range(0, nsamp)
     ])
     series = XScatterSeries(tdict, xkey='X', openGL=True)
     self.addSeries(series[0])
     self.setAxes(series[0])
Esempio n. 5
0
 def _drawVerticalGridLines(self):
     self.vgridx = arange(0.05, 1.0, 0.05)
     self.vgridx = insert(self.vgridx, 0, [0.01, 0.02])
     self.vgridx = insert(self.vgridx, len(self.vgridx), [0.98, 0.99])
     vgridy = [self.axisY.min(), self.axisY.max()]
     self.vgridseries = []
     for val in self.vgridx:
         line = 'P' + '%02d' % round(100.0 * (1.0 - val))
         tdict = {
             'X': [distr.distrppf(self.activeProbit, val)] * 2,
             line: vgridy
         }
         self.vgridseries = self.vgridseries + XLineSeries(
             tdict, xkey='X', openGL=True)
     for i, line in enumerate(self.vgridseries):
         pen = line.pen()
         pen.setColor(self.gridcolor)
         pen.setWidthF(0.4), line.setPen(pen)
         line.setPointLabelsVisible(True)
         self.addSeries(line)
         self.setAxes(line)
         self.legend().markers(line)[0].setVisible(False)
Esempio n. 6
0
    def _drawHorizontalLabels(self):
        xmin = self.axisX.min()
        xmax = self.axisX.max()
        axisScale = 1 / (xmax - xmin
                         )  # scaler for plotted axis (reduces to 0-1.0)
        # calculate probit values to scale from grid lines insert min and max values to scale correctly
        vlabx = distr.distrppf(self.activeProbit, self.vgridx)
        vlabx = insert(vlabx, 0, xmin)
        vlabx = insert(vlabx, len(vlabx), xmax)
        vlabx = (
            vlabx - xmin
        ) * axisScale  #scale the probit value to ratios of the Xaxis length
        paw = self.plotArea().width()
        pah = self.plotArea().height()  #find the plot width and height
        # find plot bottom left corner X and Y
        pblx = self.plotArea().bottomLeft().x()
        pbly = self.plotArea().bottomLeft().y()
        # offset from axix by 10 pixels -> may need to automate this offset in future
        pbly_lab = pbly + 10
        # calculate the position on the chart in x plane with which to place each label.
        pblx = [pblx + int(paw * x) for x in vlabx[1:-1]]
        try:
            self.hlabels
        except AttributeError:
            self.hlabels = []
            for i, labx in enumerate(
                    pblx):  #run through labels and create and position them
                # label text based on P scale
                ltext = 'P' + '%02d' % round(100.0 * (1.0 - self.vgridx[i]))
                self.hlabels.append(self.scene().addText(ltext))

        for i, labx in enumerate(
                pblx):  #run through labels and create and position them
            self.hlabels[i].setPos(
                labx - 0.5 * self.hlabels[i].boundingRect().width(),
                pbly)  #centre on tick marks