Esempio n. 1
0
    def autoScale(self, maxNumSteps, x1, x2, stepSize):
        if x1 > x2:
            x1, x2 = x2, x1
        logBase = self.base()
        interval = QwtInterval(x1/np.power(logBase, self.lowerMargin()),
                               x2*np.power(logBase, self.upperMargin()))
        if interval.maxValue()/interval.minValue() < logBase:
            linearScaler = QwtLinearScaleEngine()
            linearScaler.setAttributes(self.attributes())
            linearScaler.setReference(self.reference())
            linearScaler.setMargins(self.lowerMargin(), self.upperMargin())
            
            x1, x2, stepSize = linearScaler.autoScale(maxNumSteps,
                                                      x1, x2, stepSize)
            
            linearInterval = QwtInterval(x1, x2).normalized()
            linearInterval = linearInterval.limited(LOG_MIN, LOG_MAX)
            
            if linearInterval.maxValue()/linearInterval.minValue() < logBase:
                if stepSize < 0.:
                    stepSize = -qwtLog(logBase, abs(stepSize))
                else:
                    stepSize = qwtLog(logBase, stepSize)
                return x1, x2, stepSize
            
        logRef = 1.
        if self.reference() > LOG_MIN/2:
            logRef = min([self.reference(), LOG_MAX/2])
        
        if self.testAttribute(QwtScaleEngine.Symmetric):
            delta = max([interval.maxValue()/logRef,
                         logRef/interval.minValue()])
            interval.setInterval(logRef/delta, logRef*delta)
        
        if self.testAttribute(QwtScaleEngine.IncludeReference):
            interval = interval.extend(logRef)

        interval = interval.limited(LOG_MIN, LOG_MAX)        
        
        if interval.width() == 0.:
            interval = self.buildInterval(interval.minValue())
        
        stepSize = self.divideInterval(
            qwtLogInterval(logBase, interval).width(), max([maxNumSteps, 1]))
        if stepSize < 1.:
            stepSize = 1.
        
        if not self.testAttribute(QwtScaleEngine.Floating):
            interval = self.align(interval, stepSize)
        
        x1 = interval.minValue()
        x2 = interval.maxValue()
        
        if self.testAttribute(QwtScaleEngine.Inverted):
            x1, x2 = x2, x1
            stepSize = -stepSize
Esempio n. 2
0
    def autoScale(self, maxNumSteps, x1, x2, stepSize):
        if x1 > x2:
            x1, x2 = x2, x1
        logBase = self.base()
        interval = QwtInterval(x1 / np.power(logBase, self.lowerMargin()),
                               x2 * np.power(logBase, self.upperMargin()))
        if interval.maxValue() / interval.minValue() < logBase:
            linearScaler = QwtLinearScaleEngine()
            linearScaler.setAttributes(self.attributes())
            linearScaler.setReference(self.reference())
            linearScaler.setMargins(self.lowerMargin(), self.upperMargin())

            x1, x2, stepSize = linearScaler.autoScale(maxNumSteps, x1, x2,
                                                      stepSize)

            linearInterval = QwtInterval(x1, x2).normalized()
            linearInterval = linearInterval.limited(LOG_MIN, LOG_MAX)

            if linearInterval.maxValue() / linearInterval.minValue() < logBase:
                if stepSize < 0.:
                    stepSize = -qwtLog(logBase, abs(stepSize))
                else:
                    stepSize = qwtLog(logBase, stepSize)
                return x1, x2, stepSize

        logRef = 1.
        if self.reference() > LOG_MIN / 2:
            logRef = min([self.reference(), LOG_MAX / 2])

        if self.testAttribute(QwtScaleEngine.Symmetric):
            delta = max(
                [interval.maxValue() / logRef, logRef / interval.minValue()])
            interval.setInterval(logRef / delta, logRef * delta)

        if self.testAttribute(QwtScaleEngine.IncludeReference):
            interval = interval.extend(logRef)

        interval = interval.limited(LOG_MIN, LOG_MAX)

        if interval.width() == 0.:
            interval = self.buildInterval(interval.minValue())

        stepSize = self.divideInterval(
            qwtLogInterval(logBase, interval).width(), max([maxNumSteps, 1]))
        if stepSize < 1.:
            stepSize = 1.

        if not self.testAttribute(QwtScaleEngine.Floating):
            interval = self.align(interval, stepSize)

        x1 = interval.minValue()
        x2 = interval.maxValue()

        if self.testAttribute(QwtScaleEngine.Inverted):
            x1, x2 = x2, x1
            stepSize = -stepSize
Esempio n. 3
0
    def divideScale(self, x1, x2, maxMajorSteps, maxMinorSteps, stepSize=0.):
        """
        Calculate a scale division for an interval

        :param float x1: First interval limit
        :param float x2: Second interval limit
        :param int maxMajorSteps: Maximum for the number of major steps
        :param int maxMinorSteps: Maximum number of minor steps
        :param float stepSize: Step size. If stepSize == 0.0, the scaleEngine calculates one
        :return: Calculated scale division
        """
        interval = QwtInterval(x1, x2).normalized()
        interval = interval.limited(LOG_MIN, LOG_MAX)
        
        if interval.width() <= 0:
            return QwtScaleDiv()
        
        logBase = self.base()
        
        if interval.maxValue()/interval.minValue() < logBase:
            linearScaler = QwtLinearScaleEngine()
            linearScaler.setAttributes(self.attributes())
            linearScaler.setReference(self.reference())
            linearScaler.setMargins(self.lowerMargin(), self.upperMargin())
            
            if stepSize != 0.:
                if stepSize < 0.:
                    stepSize = -np.power(logBase, -stepSize)
                else:
                    stepSize = np.power(logBase, stepSize)
            
            return linearScaler.divideScale(x1, x2, maxMajorSteps,
                                            maxMinorSteps, stepSize)
        
        stepSize = abs(stepSize)
        if stepSize == 0.:
            if maxMajorSteps < 1:
                maxMajorSteps = 1
            stepSize = self.divideInterval(
                    qwtLogInterval(logBase, interval).width(), maxMajorSteps)
            if stepSize < 1.:
                stepSize = 1.
        
        scaleDiv = QwtScaleDiv()
        if stepSize != 0.:
            ticks = self.buildTicks(interval, stepSize, maxMinorSteps)
            scaleDiv = QwtScaleDiv(interval, ticks)
        
        if x1 > x2:
            scaleDiv.invert()
        
        return scaleDiv
Esempio n. 4
0
    def divideScale(self, x1, x2, maxMajorSteps, maxMinorSteps, stepSize=0.):
        """
        Calculate a scale division for an interval

        :param float x1: First interval limit
        :param float x2: Second interval limit
        :param int maxMajorSteps: Maximum for the number of major steps
        :param int maxMinorSteps: Maximum number of minor steps
        :param float stepSize: Step size. If stepSize == 0.0, the scaleEngine calculates one
        :return: Calculated scale division
        """
        interval = QwtInterval(x1, x2).normalized()
        interval = interval.limited(LOG_MIN, LOG_MAX)
        
        if interval.width() <= 0:
            return QwtScaleDiv()
        
        logBase = self.base()
        
        if interval.maxValue()/interval.minValue() < logBase:
            linearScaler = QwtLinearScaleEngine()
            linearScaler.setAttributes(self.attributes())
            linearScaler.setReference(self.reference())
            linearScaler.setMargins(self.lowerMargin(), self.upperMargin())
            
            if stepSize != 0.:
                if stepSize < 0.:
                    stepSize = -np.power(logBase, -stepSize)
                else:
                    stepSize = np.power(logBase, stepSize)
            
            return linearScaler.divideScale(x1, x2, maxMajorSteps,
                                            maxMinorSteps, stepSize)
        
        stepSize = abs(stepSize)
        if stepSize == 0.:
            if maxMajorSteps < 1:
                maxMajorSteps = 1
            stepSize = self.divideInterval(
                    qwtLogInterval(logBase, interval).width(), maxMajorSteps)
            if stepSize < 1.:
                stepSize = 1.
        
        scaleDiv = QwtScaleDiv()
        if stepSize != 0.:
            ticks = self.buildTicks(interval, stepSize, maxMinorSteps)
            scaleDiv = QwtScaleDiv(interval, ticks)
        
        if x1 > x2:
            scaleDiv.invert()
        
        return scaleDiv
Esempio n. 5
0
 def divideScale(self, x1, x2, maxMajorSteps, maxMinorSteps, stepSize=0.):
     interval = QwtInterval(x1, x2).normalized()
     interval = interval.limited(LOG_MIN, LOG_MAX)
     
     if interval.width() <= 0:
         return QwtScaleDiv()
     
     logBase = self.base()
     
     if interval.maxValue()/interval.minValue() < logBase:
         linearScaler = QwtLinearScaleEngine()
         linearScaler.setAttributes(self.attributes())
         linearScaler.setReference(self.reference())
         linearScaler.setMargins(self.lowerMargin(), self.upperMargin())
         
         if stepSize != 0.:
             if stepSize < 0.:
                 stepSize = -np.power(logBase, -stepSize)
             else:
                 stepSize = np.power(logBase, stepSize)
         
         return linearScaler.divideScale(x1, x2, maxMajorSteps,
                                         maxMinorSteps, stepSize)
     
     stepSize = abs(stepSize)
     if stepSize == 0.:
         if maxMajorSteps < 1:
             maxMajorSteps = 1
         stepSize = self.divideInterval(
                 qwtLogInterval(logBase, interval).width(), maxMajorSteps)
         if stepSize < 1.:
             stepSize = 1.
     
     scaleDiv = QwtScaleDiv()
     if stepSize != 0.:
         ticks = self.buildTicks(interval, stepSize, maxMinorSteps)
         scaleDiv = QwtScaleDiv(interval, ticks)
     
     if x1 > x2:
         scaleDiv.invert()
     
     return scaleDiv
Esempio n. 6
0
    def divideScale(self, x1, x2, maxMajorSteps, maxMinorSteps, stepSize=0.):
        interval = QwtInterval(x1, x2).normalized()
        interval = interval.limited(LOG_MIN, LOG_MAX)

        if interval.width() <= 0:
            return QwtScaleDiv()

        logBase = self.base()

        if interval.maxValue() / interval.minValue() < logBase:
            linearScaler = QwtLinearScaleEngine()
            linearScaler.setAttributes(self.attributes())
            linearScaler.setReference(self.reference())
            linearScaler.setMargins(self.lowerMargin(), self.upperMargin())

            if stepSize != 0.:
                if stepSize < 0.:
                    stepSize = -np.power(logBase, -stepSize)
                else:
                    stepSize = np.power(logBase, stepSize)

            return linearScaler.divideScale(x1, x2, maxMajorSteps,
                                            maxMinorSteps, stepSize)

        stepSize = abs(stepSize)
        if stepSize == 0.:
            if maxMajorSteps < 1:
                maxMajorSteps = 1
            stepSize = self.divideInterval(
                qwtLogInterval(logBase, interval).width(), maxMajorSteps)
            if stepSize < 1.:
                stepSize = 1.

        scaleDiv = QwtScaleDiv()
        if stepSize != 0.:
            ticks = self.buildTicks(interval, stepSize, maxMinorSteps)
            scaleDiv = QwtScaleDiv(interval, ticks)

        if x1 > x2:
            scaleDiv.invert()

        return scaleDiv
Esempio n. 7
0
    def autoScale(self, maxNumSteps, x1, x2, stepSize):
        """
        Align and divide an interval

        :param int maxNumSteps: Max. number of steps
        :param float x1: First limit of the interval (In/Out)
        :param float x2: Second limit of the interval (In/Out)
        :param float stepSize: Step size
        :return: tuple (x1, x2, stepSize)
        
        .. seealso::
            
            :py:meth:`setAttribute()`
        """
        if x1 > x2:
            x1, x2 = x2, x1
        logBase = self.base()
        interval = QwtInterval(
            x1 / math.pow(logBase, self.lowerMargin()),
            x2 * math.pow(logBase, self.upperMargin()),
        )
        interval = interval.limited(LOG_MIN, LOG_MAX)
        if interval.maxValue() / interval.minValue() < logBase:
            linearScaler = QwtLinearScaleEngine()
            linearScaler.setAttributes(self.attributes())
            linearScaler.setReference(self.reference())
            linearScaler.setMargins(self.lowerMargin(), self.upperMargin())

            x1, x2, stepSize = linearScaler.autoScale(maxNumSteps, x1, x2,
                                                      stepSize)

            linearInterval = QwtInterval(x1, x2).normalized()
            linearInterval = linearInterval.limited(LOG_MIN, LOG_MAX)

            if linearInterval.maxValue() / linearInterval.minValue() < logBase:
                if stepSize < 0.0:
                    stepSize = -math.log(abs(stepSize), logBase)
                else:
                    stepSize = math.log(stepSize, logBase)
                return x1, x2, stepSize

        logRef = 1.0
        if self.reference() > LOG_MIN / 2:
            logRef = min([self.reference(), LOG_MAX / 2])

        if self.testAttribute(QwtScaleEngine.Symmetric):
            delta = max(
                [interval.maxValue() / logRef, logRef / interval.minValue()])
            interval.setInterval(logRef / delta, logRef * delta)

        if self.testAttribute(QwtScaleEngine.IncludeReference):
            interval = interval.extend(logRef)

        interval = interval.limited(LOG_MIN, LOG_MAX)

        if interval.width() == 0.0:
            interval = self.buildInterval(interval.minValue())

        stepSize = self.divideInterval(
            qwtLogInterval(logBase, interval).width(), max([maxNumSteps, 1]))
        if stepSize < 1.0:
            stepSize = 1.0

        if not self.testAttribute(QwtScaleEngine.Floating):
            interval = self.align(interval, stepSize)

        x1 = interval.minValue()
        x2 = interval.maxValue()

        if self.testAttribute(QwtScaleEngine.Inverted):
            x1, x2 = x2, x1
            stepSize = -stepSize

        return x1, x2, stepSize
Esempio n. 8
0
    def autoScale(self, maxNumSteps, x1, x2, stepSize):
        """
        Align and divide an interval

        :param int maxNumSteps: Max. number of steps
        :param float x1: First limit of the interval (In/Out)
        :param float x2: Second limit of the interval (In/Out)
        :param float stepSize: Step size
        :return: tuple (x1, x2, stepSize)
        
        .. seealso::
            
            :py:meth:`setAttribute()`
        """
        if x1 > x2:
            x1, x2 = x2, x1
        logBase = self.base()
        interval = QwtInterval(x1 / np.power(logBase, self.lowerMargin()), x2 * np.power(logBase, self.upperMargin()))
        if interval.maxValue() / interval.minValue() < logBase:
            linearScaler = QwtLinearScaleEngine()
            linearScaler.setAttributes(self.attributes())
            linearScaler.setReference(self.reference())
            linearScaler.setMargins(self.lowerMargin(), self.upperMargin())

            x1, x2, stepSize = linearScaler.autoScale(maxNumSteps, x1, x2, stepSize)

            linearInterval = QwtInterval(x1, x2).normalized()
            linearInterval = linearInterval.limited(LOG_MIN, LOG_MAX)

            if linearInterval.maxValue() / linearInterval.minValue() < logBase:
                if stepSize < 0.0:
                    stepSize = -qwtLog(logBase, abs(stepSize))
                else:
                    stepSize = qwtLog(logBase, stepSize)
                return x1, x2, stepSize

        logRef = 1.0
        if self.reference() > LOG_MIN / 2:
            logRef = min([self.reference(), LOG_MAX / 2])

        if self.testAttribute(QwtScaleEngine.Symmetric):
            delta = max([interval.maxValue() / logRef, logRef / interval.minValue()])
            interval.setInterval(logRef / delta, logRef * delta)

        if self.testAttribute(QwtScaleEngine.IncludeReference):
            interval = interval.extend(logRef)

        interval = interval.limited(LOG_MIN, LOG_MAX)

        if interval.width() == 0.0:
            interval = self.buildInterval(interval.minValue())

        stepSize = self.divideInterval(qwtLogInterval(logBase, interval).width(), max([maxNumSteps, 1]))
        if stepSize < 1.0:
            stepSize = 1.0

        if not self.testAttribute(QwtScaleEngine.Floating):
            interval = self.align(interval, stepSize)

        x1 = interval.minValue()
        x2 = interval.maxValue()

        if self.testAttribute(QwtScaleEngine.Inverted):
            x1, x2 = x2, x1
            stepSize = -stepSize

        return x1, x2, stepSize