Пример #1
0
    def divideScale(self, x1, x2, maxMajorSteps, maxMinorSteps, stepSize=0.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()
        if interval.width() <= 0:
            return QwtScaleDiv()
        stepSize = abs(stepSize)
        if stepSize == 0.0:
            if maxMajorSteps < 1:
                maxMajorSteps = 1
            stepSize = divideInterval(interval.width(), maxMajorSteps,
                                      self.base())
        scaleDiv = QwtScaleDiv()
        if stepSize != 0.0:
            ticks = self.buildTicks(interval, stepSize, maxMinorSteps)
            scaleDiv = QwtScaleDiv(interval, ticks)
        if x1 > x2:
            scaleDiv.invert()
        return scaleDiv
Пример #2
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()
        if interval.width() <= 0:
            return QwtScaleDiv()
        stepSize = abs(stepSize)
        if stepSize == 0.:
            if maxMajorSteps < 1:
                maxMajorSteps = 1
            stepSize = divideInterval(interval.width(), maxMajorSteps,
                                      self.base())
        scaleDiv = QwtScaleDiv()
        if stepSize != 0.:
            ticks = self.buildTicks(interval, stepSize, maxMinorSteps)
            scaleDiv = QwtScaleDiv(interval, ticks)
        if x1 > x2:
            scaleDiv.invert()
        return scaleDiv
Пример #3
0
class QwtColumnRect(object):
    
    # enum Direction
    LeftToRight, RightToLeft, BottomToTop, TopToBottom = list(range(4))
    
    def __init__(self):
        self.hInterval = QwtInterval()
        self.vInterval = QwtInterval()
        self.direction = 0
        
    def toRect(self):
        r = QRectF(self.hInterval.minValue(), self.vInterval.minValue(),
                   self.hInterval.maxValue()-self.hInterval.minValue(),
                   self.vInterval.maxValue()-self.vInterval.minValue())
        r = r.normalized()
        if self.hInterval.borderFlags() & QwtInterval.ExcludeMinimum:
            r.adjust(1, 0, 0, 0)
        if self.hInterval.borderFlags() & QwtInterval.ExcludeMaximum:
            r.adjust(0, 0, -1, 0)
        if self.vInterval.borderFlags() & QwtInterval.ExcludeMinimum:
            r.adjust(0, 1, 0, 0)
        if self.vInterval.borderFlags() & QwtInterval.ExcludeMaximum:
            r.adjust(0, 0, 0, -1)
        return r
    
    def orientation(self):
        if self.direction in (self.LeftToRight, self.RightToLeft):
            return Qt.Horizontal
        return Qt.Vertical
Пример #4
0
class QwtColumnRect(object):

    # enum Direction
    LeftToRight, RightToLeft, BottomToTop, TopToBottom = list(range(4))

    def __init__(self):
        self.hInterval = QwtInterval()
        self.vInterval = QwtInterval()
        self.direction = 0

    def toRect(self):
        r = QRectF(self.hInterval.minValue(), self.vInterval.minValue(),
                   self.hInterval.maxValue() - self.hInterval.minValue(),
                   self.vInterval.maxValue() - self.vInterval.minValue())
        r = r.normalized()
        if self.hInterval.borderFlags() & QwtInterval.ExcludeMinimum:
            r.adjust(1, 0, 0, 0)
        if self.hInterval.borderFlags() & QwtInterval.ExcludeMaximum:
            r.adjust(0, 0, -1, 0)
        if self.vInterval.borderFlags() & QwtInterval.ExcludeMinimum:
            r.adjust(0, 1, 0, 0)
        if self.vInterval.borderFlags() & QwtInterval.ExcludeMaximum:
            r.adjust(0, 0, 0, -1)
        return r

    def orientation(self):
        if self.direction in (self.LeftToRight, self.RightToLeft):
            return Qt.Horizontal
        return Qt.Vertical
Пример #5
0
 def buildInterval(self, value):
     if value == 0.:
         delta = .5
     else:
         delta = abs(.5 * value)
     if DBL_MAX - delta < value:
         return QwtInterval(DBL_MAX - delta, DBL_MAX)
     if -DBL_MAX + delta > value:
         return QwtInterval(-DBL_MAX, -DBL_MAX + delta)
     return QwtInterval(value - delta, value + delta)
Пример #6
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
Пример #7
0
 def __init__(self, *args):
     if len(args) == 0:
         self.value = 0.
         self.interval = QwtInterval()
     elif len(args) == 2:
         v, intv = args
         self.value = v
         self.interval = intv
     elif len(args) == 3:
         v, min_, max_ = args
         self.value = v
         self.interval = QwtInterval(min_, max_)
     else:
         raise TypeError("%s() takes 0, 2 or 3 argument(s) (%s given)"\
                         % (self.__class__.__name__, len(args)))
Пример #8
0
 def divideScale(self, x1, x2, maxMajorSteps, maxMinorSteps, stepSize=0.):
     interval = QwtInterval(x1, x2).normalized()
     if interval.width() <= 0:
         return QwtScaleDiv()
     stepSize = abs(stepSize)
     if stepSize == 0.:
         if maxMajorSteps < 1:
             maxMajorSteps = 1
         stepSize = divideInterval(interval.width(), maxMajorSteps,
                                   self.base())
     scaleDiv = QwtScaleDiv()
     if stepSize != 0.:
         ticks = self.buildTicks(interval, stepSize, maxMinorSteps)
         scaleDiv = QwtScaleDiv(interval, ticks)
     if x1 > x2:
         scaleDiv.invert()
     return scaleDiv
Пример #9
0
 def divideScale(self, x1, x2, maxMajorSteps, maxMinorSteps, stepSize=0.):
     interval = QwtInterval(x1, x2).normalized()
     if interval.width() <= 0:
         return QwtScaleDiv()
     stepSize = abs(stepSize)
     if stepSize == 0.:
         if maxMajorSteps < 1:
             maxMajorSteps = 1
         stepSize = divideInterval(interval.width(), maxMajorSteps,
                                   self.base())
     scaleDiv = QwtScaleDiv()
     if stepSize != 0.:
         ticks = self.buildTicks(interval, stepSize, maxMinorSteps)
         scaleDiv = QwtScaleDiv(interval, ticks)
     if x1 > x2:
         scaleDiv.invert()
     return scaleDiv
Пример #10
0
 def boundingInterval(self):
     minY = self.open
     minY = min([minY, self.high])
     minY = min([minY, self.low])
     minY = min([minY, self.close])
     maxY = self.open
     maxY = max([maxY, self.high])
     maxY = max([maxY, self.low])
     maxY = max([maxY, self.close])
     return QwtInterval(minY, maxY)
Пример #11
0
    def buildInterval(self, value):
        """
        Build an interval around a value

        In case of v == 0.0 the interval is [-0.5, 0.5],
        otherwide it is [0.5 * v, 1.5 * v]
        
        :param float value: Initial value
        :return: Calculated interval
        """
        if value == 0.0:
            delta = 0.5
        else:
            delta = abs(0.5 * value)
        if DBL_MAX - delta < value:
            return QwtInterval(DBL_MAX - delta, DBL_MAX)
        if -DBL_MAX + delta > value:
            return QwtInterval(-DBL_MAX, -DBL_MAX + delta)
        return QwtInterval(value - delta, value + delta)
Пример #12
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
Пример #13
0
 def align(self, interval, stepSize):
     x1 = interval.minValue()
     x2 = interval.maxValue()
     if -DBL_MAX + stepSize <= x1:
         x = floorEps(x1, stepSize)
         if qwtFuzzyCompare(x1, x, stepSize) != 0:
             x1 = x
     if DBL_MAX - stepSize >= x2:
         x = ceilEps(x2, stepSize)
         if qwtFuzzyCompare(x2, x, stepSize) != 0:
             x2 = x
     return QwtInterval(x1, x2)
Пример #14
0
    def align(self, interval, stepSize):
        intv = qwtLogInterval(self.base(), interval)

        x1 = floorEps(intv.minValue(), stepSize)
        if qwtFuzzyCompare(interval.minValue(), x1, stepSize) == 0:
            x1 = interval.minValue()

        x2 = ceilEps(intv.maxValue(), stepSize)
        if qwtFuzzyCompare(interval.maxValue(), x2, stepSize) == 0:
            x2 = interval.maxValue()

        return qwtPowInterval(self.base(), QwtInterval(x1, x2))
Пример #15
0
    def updateAxes(self):
        intv = [QwtInterval() for _i in range(self.axisCnt)]
        itmList = self.itemList()
        for item in itmList:
            if not item.testItemAttribute(QwtPlotItem.AutoScale):
                continue
            if not item.isVisible():
                continue
            if self.axisAutoScale(item.xAxis()) or self.axisAutoScale(item.yAxis()):
                rect = item.boundingRect()
                if rect.width() >= 0.:
                    intv[item.xAxis()] |= QwtInterval(rect.left(), rect.right())
                if rect.height() >= 0.:
                    intv[item.yAxis()] |= QwtInterval(rect.top(), rect.bottom())
        for axisId in range(self.axisCnt):
            d = self.__axisData[axisId]
            minValue = d.minValue
            maxValue = d.maxValue
            stepSize = d.stepSize
            if d.doAutoScale and intv[axisId].isValid():
                d.isValid = False
                minValue = intv[axisId].minValue()
                maxValue = intv[axisId].maxValue()
                d.scaleEngine.autoScale(d.maxMajor, minValue, maxValue, stepSize)
            if not d.isValid:
                d.scaleDiv = d.scaleEngine.divideScale(minValue, maxValue,
                                           d.maxMajor, d.maxMinor, stepSize)
                d.isValid = True
            scaleWidget = self.axisWidget(axisId)
            scaleWidget.setScaleDiv(d.scaleDiv)

            #TODO: see when it is *really* necessary to update border dist
#            startDist, endDist = scaleWidget.getBorderDistHint()
#            scaleWidget.setBorderDist(startDist, endDist)

        for item in itmList:
            if item.testItemInterest(QwtPlotItem.ScaleInterest):
                item.updateScaleDiv(self.axisScaleDiv(item.xAxis()),
                                    self.axisScaleDiv(item.yAxis()))
Пример #16
0
class QwtSyntheticPointData(QwtSeriesData):
    def __init__(self, size, interval):
        QwtSeriesData.__init__(self)
        self.__size = size
        self.__interval = interval
        self.__rectOfInterest = None
        self.__intervalOfInterest = None

    def setSize(self, size):
        self.__size = size

    def size(self):
        return self.__size

    def setInterval(self, interval):
        self.__interval = interval.normalized()

    def interval(self):
        return self.__interval

    def setRectOfInterest(self, rect):
        self.__rectOfInterest = rect
        self.__intervalOfInterest = QwtInterval(rect.left(),
                                                rect.right()).normalized()

    def rectOfInterest(self):
        return self.__rectOfInterest

    def boundingRect(self):
        if self.__size == 0 or\
           not (self.__interval.isValid() or self.__intervalOfInterest.isValid()):
            return QRectF(1.0, 1.0, -2.0, -2.0)
        return qwtBoundingRect(self)

    def sample(self, index):
        if index >= self.__size:
            return QPointF(0, 0)
        xValue = self.x(index)
        yValue = self.y(xValue)
        return QPointF(xValue, yValue)

    def x(self, index):
        if self.__interval.isValid():
            interval = self.__interval
        else:
            interval = self.__intervalOfInterest
        if not interval.isValid() or self.__size == 0 or index >= self.__size:
            return 0.
        dx = interval.width() / self.__size
        return interval.minValue() + index * dx
Пример #17
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
Пример #18
0
    def align(self, interval, stepSize):
        """
        Align an interval to a step size

        The limits of an interval are aligned that both are integer
        multiples of the step size.
        
        :param qwt.interval.QwtInterval interval: Interval
        :param float stepSize: Step size
        :return: Aligned interval
        """
        x1 = interval.minValue()
        x2 = interval.maxValue()
        if -DBL_MAX+stepSize <= x1:
            x = floorEps(x1, stepSize)
            if qwtFuzzyCompare(x1, x, stepSize) != 0:
                x1 = x
        if DBL_MAX-stepSize >= x2:
            x = ceilEps(x2, stepSize)
            if qwtFuzzyCompare(x2, x, stepSize) != 0:
                x2 = x
        return QwtInterval(x1, x2)
Пример #19
0
    def align(self, interval, stepSize):
        """
        Align an interval to a step size

        The limits of an interval are aligned that both are integer
        multiples of the step size.
        
        :param qwt.interval.QwtInterval interval: Interval
        :param float stepSize: Step size
        :return: Aligned interval
        """
        intv = qwtLogInterval(self.base(), interval)

        x1 = floorEps(intv.minValue(), stepSize)
        if qwtFuzzyCompare(interval.minValue(), x1, stepSize) == 0:
            x1 = interval.minValue()

        x2 = ceilEps(intv.maxValue(), stepSize)
        if qwtFuzzyCompare(interval.maxValue(), x2, stepSize) == 0:
            x2 = interval.maxValue()

        return qwtPowInterval(self.base(), QwtInterval(x1, x2))
Пример #20
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
Пример #21
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()`
        """
        interval = QwtInterval(x1, x2)
        interval = interval.normalized()
        interval.setMinValue(interval.minValue() - self.lowerMargin())
        interval.setMaxValue(interval.maxValue() + self.upperMargin())
        if self.testAttribute(QwtScaleEngine.Symmetric):
            interval = interval.symmetrize(self.reference())
        if self.testAttribute(QwtScaleEngine.IncludeReference):
            interval = interval.extend(self.reference())
        if interval.width() == 0.0:
            interval = self.buildInterval(interval.minValue())
        stepSize = divideInterval(interval.width(), max([maxNumSteps, 1]),
                                  self.base())
        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
Пример #22
0
def qwtLogInterval(base, interval):
    return QwtInterval(math.log(interval.minValue(), base),
                       math.log(interval.maxValue(), base))
Пример #23
0
 def autoScale(self, maxNumSteps, x1, x2, stepSize):
     interval = QwtInterval(x1, x2)
     interval = interval.normalized()
     interval.setMinValue(interval.minValue()-self.lowerMargin())
     interval.setMaxValue(interval.maxValue()+self.upperMargin())
     if self.testAttribute(QwtScaleEngine.Symmetric):
         interval = interval.symmetrize(self.reference())
     if self.testAttribute(QwtScaleEngine.IncludeReference):
         interval = interval.extend(self.reference())
     if interval.width() == 0.:
         interval = self.buildInterval(interval.minValue())
     stepSize = divideInterval(interval.width(),
                               max([maxNumSteps, 1]), self.base())
     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
Пример #24
0
def qwtPowInterval(base, interval):
    return QwtInterval(np.power(base, interval.minValue()),
                       np.power(base, interval.maxValue()))
Пример #25
0
 def axisInterval(self, axisId):
     if self.axisValid(axisId):
         return self.axisWidget(axisId).scaleDiv.interval()
     else:
         return QwtInterval()
Пример #26
0
 def setRectOfInterest(self, rect):
     self.__rectOfInterest = rect
     self.__intervalOfInterest = QwtInterval(rect.left(),
                                             rect.right()).normalized()
Пример #27
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
Пример #28
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()))
        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.:
                    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

        return x1, x2, stepSize
Пример #29
0
 def interval(self):
     return QwtInterval(self.__lowerBound, self.__upperBound)
Пример #30
0
def qwtLogInterval(base, interval):
    return QwtInterval(qwtLog(base, interval.minValue()),
                       qwtLog(base, interval.maxValue()))
Пример #31
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()`
        """
        interval = QwtInterval(x1, x2)
        interval = interval.normalized()
        interval.setMinValue(interval.minValue()-self.lowerMargin())
        interval.setMaxValue(interval.maxValue()+self.upperMargin())
        if self.testAttribute(QwtScaleEngine.Symmetric):
            interval = interval.symmetrize(self.reference())
        if self.testAttribute(QwtScaleEngine.IncludeReference):
            interval = interval.extend(self.reference())
        if interval.width() == 0.:
            interval = self.buildInterval(interval.minValue())
        stepSize = divideInterval(interval.width(),
                                  max([maxNumSteps, 1]), self.base())
        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
Пример #32
0
 def __init__(self):
     self.hInterval = QwtInterval()
     self.vInterval = QwtInterval()
     self.direction = 0
Пример #33
0
def qwtPowInterval(base, interval):
    return QwtInterval(math.pow(base, interval.minValue()),
                       math.pow(base, interval.maxValue()))
Пример #34
0
 def __init__(self):
     self.hInterval = QwtInterval()
     self.vInterval = QwtInterval()
     self.direction = 0
Пример #35
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
Пример #36
0
 def interval(self):
     """
     :return: Interval
     """
     return QwtInterval(self.__lowerBound, self.__upperBound)
Пример #37
0
 def __init__(self):
     self.isEnabled = None
     self.width = None
     self.interval = QwtInterval()
     self.colorMap = QwtColorMap()
Пример #38
0
 def autoScale(self, maxNumSteps, x1, x2, stepSize):
     interval = QwtInterval(x1, x2)
     interval = interval.normalized()
     interval.setMinValue(interval.minValue() - self.lowerMargin())
     interval.setMaxValue(interval.maxValue() + self.upperMargin())
     if self.testAttribute(QwtScaleEngine.Symmetric):
         interval = interval.symmetrize(self.reference())
     if self.testAttribute(QwtScaleEngine.IncludeReference):
         interval = interval.extend(self.reference())
     if interval.width() == 0.:
         interval = self.buildInterval(interval.minValue())
     stepSize = divideInterval(interval.width(), max([maxNumSteps, 1]),
                               self.base())
     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