Example #1
0
    def __init__(self, *args):
        QFrame.__init__(self, *args)

        self.xMap = QwtScaleMap()
        self.xMap.setScaleInterval(-0.5, 10.5)
        self.yMap = QwtScaleMap()
        self.yMap.setScaleInterval(-1.1, 1.1)

        # frame style
        self.setFrameStyle(QFrame.Box | QFrame.Raised)
        self.setLineWidth(2)
        self.setMidLineWidth(3)

        # calculate values
        self.x = np.arange(0, 10.0, 10.0 / 27)
        self.y = np.sin(self.x) * np.cos(2 * self.x)

        # make curves with different styles
        self.curves = []
        self.titles = []
        # curve 1
        self.titles.append('Style: Sticks, Symbol: Ellipse')
        curve = QwtPlotCurve()
        curve.setPen(QPen(Qt.red))
        curve.setStyle(QwtPlotCurve.Sticks)
        curve.setSymbol(
            QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.yellow), QPen(Qt.blue),
                      QSize(5, 5)))
        self.curves.append(curve)
        # curve 2
        self.titles.append('Style: Lines, Symbol: None')
        curve = QwtPlotCurve()
        curve.setPen(QPen(Qt.darkBlue))
        curve.setStyle(QwtPlotCurve.Lines)
        self.curves.append(curve)
        # curve 3
        self.titles.append('Style: Lines, Symbol: None, Antialiased')
        curve = QwtPlotCurve()
        curve.setPen(QPen(Qt.darkBlue))
        curve.setStyle(QwtPlotCurve.Lines)
        curve.setRenderHint(QwtPlotItem.RenderAntialiased)
        self.curves.append(curve)
        # curve 4
        self.titles.append('Style: Steps, Symbol: None')
        curve = QwtPlotCurve()
        curve.setPen(QPen(Qt.darkCyan))
        curve.setStyle(QwtPlotCurve.Steps)
        self.curves.append(curve)
        # curve 5
        self.titles.append('Style: NoCurve, Symbol: XCross')
        curve = QwtPlotCurve()
        curve.setStyle(QwtPlotCurve.NoCurve)
        curve.setSymbol(
            QwtSymbol(QwtSymbol.XCross, QBrush(), QPen(Qt.darkMagenta),
                      QSize(5, 5)))
        self.curves.append(curve)

        # attach data, using Numeric
        for curve in self.curves:
            curve.setData(self.x, self.y)
Example #2
0
    def __init__(self, *args):
        QFrame.__init__(self, *args)

        self.setFrameStyle(QFrame.Box | QFrame.Raised)
        self.setLineWidth(2)
        self.setMidLineWidth(3)

        p = QPalette()
        p.setColor(self.backgroundRole(), QColor(30, 30, 50))
        self.setPalette(p)
        # make curves and maps
        self.tuples = []
        # curve 1
        curve = QwtPlotCurve()
        curve.setPen(QPen(QColor(150, 150, 200), 2))
        curve.setStyle(QwtPlotCurve.Lines)
        curve.setSymbol(QwtSymbol(QwtSymbol.XCross,
                                      QBrush(),
                                      QPen(Qt.yellow, 2),
                                      QSize(7, 7)))
        self.tuples.append((curve,
                            QwtScaleMap(0, 100, -1.5, 1.5),
                            QwtScaleMap(0, 100, 0.0, 2*np.pi)))
        # curve 2
        curve = QwtPlotCurve()
        curve.setPen(QPen(QColor(200, 150, 50),
                                1,
                                Qt.DashDotDotLine))
        curve.setStyle(QwtPlotCurve.Sticks)
        curve.setSymbol(QwtSymbol(QwtSymbol.Ellipse,
                                      QBrush(Qt.blue),
                                      QPen(Qt.yellow),
                                      QSize(5, 5)))
        self.tuples.append((curve,
                            QwtScaleMap(0, 100, 0.0, 2*np.pi),
                            QwtScaleMap(0, 100, -3.0, 1.1)))
        # curve 3
        curve = QwtPlotCurve()
        curve.setPen(QPen(QColor(100, 200, 150)))
        curve.setStyle(QwtPlotCurve.Lines)
        self.tuples.append((curve,
                            QwtScaleMap(0, 100, -1.1, 3.0),
                            QwtScaleMap(0, 100, -1.1, 3.0)))
        # curve 4
        curve = QwtPlotCurve()
        curve.setPen(QPen(Qt.red))
        curve.setStyle(QwtPlotCurve.Lines)
        self.tuples.append((curve,
                            QwtScaleMap(0, 100, -5.0, 1.1),
                            QwtScaleMap(0, 100, -1.1, 5.0)))
        # data
        self.phase = 0.0
        self.base = np.arange(0.0, 2.01*np.pi, 2*np.pi/(USize-1))
        self.uval = np.cos(self.base)
        self.vval = np.sin(self.base)
        self.uval[1::2] *= 0.5
        self.vval[1::2] *= 0.5
        self.newValues()
        # start timer
        self.tid = self.startTimer(250)
Example #3
0
    def legendIcon(self, index, size):
        if size.isEmpty():
            return QwtGraphic()
        graphic = QwtGraphic()
        graphic.setDefaultSize(size)
        graphic.setRenderHint(QwtGraphic.RenderPensUnscaled, True)
        painter = QPainter(graphic)
        painter.setRenderHint(QPainter.Antialiasing,
                          self.testRenderHint(QwtPlotItem.RenderAntialiased))
        if self.__data.legendAttributes == 0 or\
           (self.__data.legendAttributes & QwtPlotCurve.LegendShowBrush):
            brush = self.__data.brush
            if brush.style() == Qt.NoBrush and self.__data.legendAttributes == 0:
                if self.style() != QwtPlotCurve.NoCurve:
                    brush = QBrush(self.pen().color())
                elif self.__data.symbol and\
                     self.__data.symbol.style() != QwtSymbol.NoSymbol:
                    brush = QBrush(self.__data.symbol.pen().color())
            if brush.style() != Qt.NoBrush:
                r = QRectF(0, 0, size.width(), size.height())
                painter.fillRect(r, brush)
        if self.__data.legendAttributes & QwtPlotCurve.LegendShowLine:
            if self.pen() != Qt.NoPen:
                pn = self.pen()
#                pn.setCapStyle(Qt.FlatCap)
                painter.setPen(pn)
                y = .5*size.height()
                QwtPainter.drawLine(painter, 0., y, size.width(), y)
        if self.__data.legendAttributes & QwtPlotCurve.LegendShowSymbol:
            if self.__data.symbol:
                r = QRectF(0, 0, size.width(), size.height())
                self.__data.symbol.drawSymbol(painter, r)
        return graphic    
Example #4
0
 def legendIcon(self, index, size):
     if size.isEmpty():
         return QwtGraphic()
     graphic = QwtGraphic()
     graphic.setDefaultSize(size)
     graphic.setRenderHint(QwtGraphic.RenderPensUnscaled, True)
     painter = QPainter(graphic)
     painter.setRenderHint(
         QPainter.Antialiasing,
         self.testRenderHint(QwtPlotItem.RenderAntialiased))
     if self.__data.legendAttributes == 0 or\
        (self.__data.legendAttributes & QwtPlotCurve.LegendShowBrush):
         brush = self.__data.brush
         if brush.style(
         ) == Qt.NoBrush and self.__data.legendAttributes == 0:
             if self.style() != QwtPlotCurve.NoCurve:
                 brush = QBrush(self.pen().color())
             elif self.__data.symbol and\
                  self.__data.symbol.style() != QwtSymbol.NoSymbol:
                 brush = QBrush(self.__data.symbol.pen().color())
         if brush.style() != Qt.NoBrush:
             r = QRectF(0, 0, size.width(), size.height())
             painter.fillRect(r, brush)
     if self.__data.legendAttributes & QwtPlotCurve.LegendShowLine:
         if self.pen() != Qt.NoPen:
             pn = self.pen()
             #                pn.setCapStyle(Qt.FlatCap)
             painter.setPen(pn)
             y = .5 * size.height()
             QwtPainter.drawLine(painter, 0., y, size.width(), y)
     if self.__data.legendAttributes & QwtPlotCurve.LegendShowSymbol:
         if self.__data.symbol:
             r = QRectF(0, 0, size.width(), size.height())
             self.__data.symbol.drawSymbol(painter, r)
     return graphic
Example #5
0
 def drawColorBar(self, painter, rect):
     h1, s1, v1, _ = self.__light.getHsv()
     h2, s2, v2, _ = self.__dark.getHsv()
     painter.save()
     painter.setClipRect(rect)
     painter.setClipping(True)
     painter.fillRect(rect, QBrush(self.__dark))
     sectionSize = 2
     if (self.__orientation == Qt.Horizontal):
         numIntervals = rect.width()/sectionSize
     else:
         numIntervals = rect.height()/sectionSize
     section = QRect()
     for i in range(int(numIntervals)):
         if self.__orientation == Qt.Horizontal:
             section.setRect(rect.x() + i*sectionSize, rect.y(),
                             sectionSize, rect.heigh())
         else:
             section.setRect(rect.x(), rect.y() + i*sectionSize,
                             rect.width(), sectionSize)
         ratio = float(i)/float(numIntervals)
         color = QColor()
         color.setHsv(h1 + int(ratio*(h2-h1) + 0.5),
                      s1 + int(ratio*(s2-s1) + 0.5),
                      v1 + int(ratio*(v2-v1) + 0.5))            
         painter.fillRect(section, color)
     painter.restore()
Example #6
0
    def setBrush(self, brush):
        """
        Assign a brush.

        In case of `brush.style() != QBrush.NoBrush`
        and `style() != QwtPlotCurve.Sticks`
        the area between the curve and the baseline will be filled.
        
        In case `not brush.color().isValid()` the area will be filled by
        `pen.color()`. The fill algorithm simply connects the first and the
        last curve point to the baseline. So the curve data has to be sorted
        (ascending or descending).
        
        :param brush: New brush
        :type brush: QBrush or QColor
        
        .. seealso::
        
            :py:meth:`brush()`, :py:meth:`setBaseline()`, :py:meth:`baseline()`
        """
        if isinstance(brush, QColor):
            brush = QBrush(brush)
        else:
            assert isinstance(brush, QBrush)
        if brush != self.__data.brush:
            self.__data.brush = brush
            self.legendChanged()
            self.itemChanged()
Example #7
0
 def drawRoundFrame(self, painter, rect, palette, lineWidth, frameStyle):
     """
     Draw a round frame
     
     :param QPainter painter: Painter
     :param QRectF rect: Target rectangle
     :param QPalette palette: `QPalette.WindowText` is used for plain borders, `QPalette.Dark` and `QPalette.Light` for raised or sunken borders
     :param int lineWidth: Line width
     :param int frameStyle: bitwise OR´ed value of `QFrame.Shape` and `QFrame.Shadow`
     """
     Plain, Sunken, Raised = list(range(3))
     style = Plain
     if (frameStyle & QFrame.Sunken) == QFrame.Sunken:
         style = Sunken
     elif (frameStyle & QFrame.Raised) == QFrame.Raised:
         style = Raised
     lw2 = .5 * lineWidth
     r = rect.adjusted(lw2, lw2, -lw2, -lw2)
     if style != Plain:
         c1 = palette.color(QPalette.Light)
         c2 = palette.color(QPalette.Dark)
         if style == Sunken:
             c1, c2 = c2, c1
         gradient = QLinearGradient(r.topLeft(), r.bottomRight())
         gradient.setColorAt(0., c1)
         gradient.setColorAt(1., c2)
         brush = QBrush(gradient)
     else:
         brush = palette.brush(QPalette.WindowText)
     painter.save()
     painter.setPen(QPen(brush, lineWidth))
     painter.drawEllipse(r)
     painter.restore()
Example #8
0
 def __init__(self, *args):
     QMainWindow.__init__(self, *args)
     self.plot = QwtPlot(self)
     self.plot.setTitle("A Simple Map Demonstration")
     self.plot.setCanvasBackground(Qt.white)
     self.plot.setAxisTitle(QwtPlot.xBottom, "x")
     self.plot.setAxisTitle(QwtPlot.yLeft, "y")
     self.plot.setAxisScale(QwtPlot.xBottom, 0.0, 1.0)
     self.plot.setAxisScale(QwtPlot.yLeft, 0.0, 1.0)
     self.setCentralWidget(self.plot)
     # Initialize map data
     self.count = self.i = 1000
     self.xs = np.zeros(self.count, np.float)
     self.ys = np.zeros(self.count, np.float)
     self.kappa = 0.2
     self.curve = QwtPlotCurve("Map")
     self.curve.attach(self.plot)
     self.curve.setSymbol(
         QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.red), QPen(Qt.blue),
                   QSize(5, 5)))
     self.curve.setPen(QPen(Qt.cyan))
     toolBar = QToolBar(self)
     self.addToolBar(toolBar)
     # 1 tick = 1 ms, 10 ticks = 10 ms (Linux clock is 100 Hz)
     self.ticks = 10
     self.tid = self.startTimer(self.ticks)
     self.timer_tic = None
     self.user_tic = None
     self.system_tic = None
     self.plot.replot()
Example #9
0
def make():
    # create a plot with a white canvas
    demo = QwtPlot(QwtText("Errorbar Demonstation"))
    demo.setCanvasBackground(Qt.white)
    demo.plotLayout().setAlignCanvasToScales(True)

    grid = QwtPlotGrid()
    grid.attach(demo)
    grid.setPen(QPen(Qt.black, 0, Qt.DotLine))

    # calculate data and errors for a curve with error bars
    x = np.arange(0, 10.1, 0.5, np.float)
    y = np.sin(x)
    dy = 0.2 * abs(y)
    # dy = (0.15 * abs(y), 0.25 * abs(y)) # uncomment for asymmetric error bars
    dx = 0.2  # all error bars the same size
    errorOnTop = False  # uncomment to draw the curve on top of the error bars
    # errorOnTop = True # uncomment to draw the error bars on top of the curve
    curve = ErrorBarPlotCurve(
        x=x,
        y=y,
        dx=dx,
        dy=dy,
        curvePen=QPen(Qt.black, 2),
        curveSymbol=QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.red),
                              QPen(Qt.black, 2), QSize(9, 9)),
        errorPen=QPen(Qt.blue, 2),
        errorCap=10,
        errorOnTop=errorOnTop,
    )
    curve.attach(demo)
    demo.resize(640, 480)
    demo.show()
    return demo
Example #10
0
def make():
    # create a plot with a white canvas
    demo = QwtPlot(QwtText("Curve Demonstation"))
    #   demo.setCanvasBackground(Qt.white)
    #   demo.plotLayout().setAlignCanvasToScales(True)

    #   grid = QwtPlotGrid()
    #   grid.attach(demo)
    #   grid.setPen(QPen(Qt.black, 0, Qt.DotLine))

    # calculate data and errors for a curve with error bars
    x = numpy.zeros(20, numpy.float32)
    y = numpy.zeros(20, numpy.float32)
    symbol_sizes = numpy.zeros(20, numpy.int32)
    symbolList = []
    for i in range(20):
        x[i] = 1.0 * i
        y[i] = 2.0 * i
        symbol_sizes[i] = 3 + i
        if i % 2 == 0:
            symbolList.append(
                QwtSymbol(QwtSymbol.UTriangle, QBrush(Qt.black),
                          QPen(Qt.black), QSize(3 + i, 3 + i)))
        else:
            symbolList.append(
                QwtSymbol(QwtSymbol.DTriangle, QBrush(Qt.red), QPen(Qt.red),
                          QSize(3 + i, 3 + i)))

    curve = QwtPlotCurveSizes(x=x, y=y, symbolSizes=symbol_sizes)
    x = x + 10
    curve1 = QwtPlotCurveSizes(x=x, y=y, symbolSizes=symbol_sizes)
    curve.setSymbol(
        QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.black), QPen(Qt.black),
                  QSize(5, 5)))
    curve.setPen(QPen(Qt.blue, 2))
    curve1.setSymbol(
        QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.red), QPen(Qt.red),
                  QSize(10, 10)))
    curve1.setPen(QPen(Qt.blue, 2))
    curve1.setSymbolList(symbolList)

    curve.attach(demo)
    curve1.attach(demo)
    demo.resize(640, 480)
    demo.show()
    return demo
Example #11
0
 def legendIcon(self, index, size):
     """
     :param int index: Index of the legend entry (ignored as there is only one)
     :param QSizeF size: Icon size
     :return: Icon representing the curve on the legend
     
     .. seealso::
     
         :py:meth:`qwt.plot.QwtPlotItem.setLegendIconSize()`,
         :py:meth:`qwt.plot.QwtPlotItem.legendData()`
     """
     if size.isEmpty():
         return QwtGraphic()
     graphic = QwtGraphic()
     graphic.setDefaultSize(size)
     graphic.setRenderHint(QwtGraphic.RenderPensUnscaled, True)
     painter = QPainter(graphic)
     painter.setRenderHint(
         QPainter.Antialiasing,
         self.testRenderHint(QwtPlotItem.RenderAntialiased))
     if self.__data.legendAttributes == 0 or\
        (self.__data.legendAttributes & QwtPlotCurve.LegendShowBrush):
         brush = self.__data.brush
         if brush.style(
         ) == Qt.NoBrush and self.__data.legendAttributes == 0:
             if self.style() != QwtPlotCurve.NoCurve:
                 brush = QBrush(self.pen().color())
             elif self.__data.symbol and\
                  self.__data.symbol.style() != QwtSymbol.NoSymbol:
                 brush = QBrush(self.__data.symbol.pen().color())
         if brush.style() != Qt.NoBrush:
             r = QRectF(0, 0, size.width(), size.height())
             painter.fillRect(r, brush)
     if self.__data.legendAttributes & QwtPlotCurve.LegendShowLine:
         if self.pen() != Qt.NoPen:
             pn = self.pen()
             #                pn.setCapStyle(Qt.FlatCap)
             painter.setPen(pn)
             y = .5 * size.height()
             painter.drawLine(0., y, size.width(), y)
     if self.__data.legendAttributes & QwtPlotCurve.LegendShowSymbol:
         if self.__data.symbol:
             r = QRectF(0, 0, size.width(), size.height())
             self.__data.symbol.drawSymbol(painter, r)
     return graphic
Example #12
0
 def __init__(self):
     QwtPlotItem_PrivateData.__init__(self)
     self.style = QwtPlotCurve.Lines
     self.baseline = 0.
     self.symbol = None
     self.attributes = 0
     self.legendAttributes = QwtPlotCurve.LegendShowLine
     self.pen = QPen(Qt.black)
     self.brush = QBrush()
Example #13
0
 def __init__(self, size):
     super(QwtStyleSheetRecorder, self).__init__()
     self.__size = size
     self.__pen = QPen()
     self.__brush = QBrush()
     self.__origin = QPointF()
     self.clipRects = []
     self.border = Border()
     self.background = Background()
Example #14
0
 def setBrush(self, brush):
     if isinstance(brush, QColor):
         brush = QBrush(brush)
     else:
         assert isinstance(brush, QBrush)
     if brush != self.__data.brush:
         self.__data.brush = brush
         self.legendChanged()
         self.itemChanged()
Example #15
0
    def legendIcon(self, index, size):
        """
        :param int index: Index of the legend entry (ignored as there is only one)
        :param QSizeF size: Icon size
        :return: Icon representing the curve on the legend
        
        .. seealso::
        
            :py:meth:`qwt.plot.QwtPlotItem.setLegendIconSize()`,
            :py:meth:`qwt.plot.QwtPlotItem.legendData()`
        """
        if size.isEmpty():
            return QwtGraphic()
        graphic = QwtGraphic()
        graphic.setDefaultSize(size)
        graphic.setRenderHint(QwtGraphic.RenderPensUnscaled, True)
        painter = QPainter(graphic)
        painter.setRenderHint(QPainter.Antialiasing,
                          self.testRenderHint(QwtPlotItem.RenderAntialiased))
        if self.__data.legendAttributes == 0 or\
           (self.__data.legendAttributes & QwtPlotCurve.LegendShowBrush):
            brush = self.__data.brush
            if brush.style() == Qt.NoBrush and self.__data.legendAttributes == 0:
                if self.style() != QwtPlotCurve.NoCurve:
                    brush = QBrush(self.pen().color())
                elif self.__data.symbol and\
                     self.__data.symbol.style() != QwtSymbol.NoSymbol:
                    brush = QBrush(self.__data.symbol.pen().color())
            if brush.style() != Qt.NoBrush:
                r = QRectF(0, 0, size.width(), size.height())
                painter.fillRect(r, brush)
        if self.__data.legendAttributes & QwtPlotCurve.LegendShowLine:
            if self.pen() != Qt.NoPen:
                pn = self.pen()
#                pn.setCapStyle(Qt.FlatCap)
                painter.setPen(pn)
                y = .5*size.height()
                painter.drawLine(0., y, size.width(), y)
        if self.__data.legendAttributes & QwtPlotCurve.LegendShowSymbol:
            if self.__data.symbol:
                r = QRectF(0, 0, size.width(), size.height())
                self.__data.symbol.drawSymbol(painter, r)
        return graphic    
Example #16
0
 def params(self, *args):
     symbols, = args
     symb1 = QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.yellow), QPen(Qt.blue),
                       QSize(5, 5))
     symb2 = QwtSymbol(QwtSymbol.XCross, QBrush(), QPen(Qt.darkMagenta),
                       QSize(5, 5))
     if symbols:
         return (
             ('Sticks', symb1),
             ('Lines', symb1),
             ('Steps', symb2),
             ('Dots', symb2),
         )
     else:
         return (
             ('Sticks', None),
             ('Lines', None),
             ('Steps', None),
             ('Dots', None),
         )
Example #17
0
 def __init__(self):
     QwtPlotItem_PrivateData.__init__(self)
     self.style = QwtPlotCurve.Lines
     self.baseline = 0.
     self.symbol = None
     self.attributes = 0
     self.paintAttributes = QwtPlotCurve.FilterPoints
     #TODO: uncomment next line when QwtClipper will be implemented
     #        self.paintAttributes = QwtPlotCurve.ClipPolygons|QwtPlotCurve.FilterPoints
     self.legendAttributes = QwtPlotCurve.LegendShowLine
     self.pen = QPen(Qt.black)
     self.brush = QBrush()
Example #18
0
 def __insertCurve(self, orientation, color, base):
     curve = QwtPlotCurve()
     curve.attach(self)
     curve.setPen(QPen(color))
     curve.setSymbol(
         QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.gray), QPen(color),
                   QSize(8, 8)))
     fixed = base * np.ones(10, np.float)
     changing = np.arange(0, 95.0, 10.0, np.float) + 5.0
     if orientation == Qt.Horizontal:
         curve.setData(changing, fixed)
     else:
         curve.setData(fixed, changing)
Example #19
0
    def draw(self, painter, xMap, yMap, rect):
        margin = 5
        pieRect = QRect()
        pieRect.setX(rect.x() + margin)
        pieRect.setY(rect.y() + margin)
        pieRect.setHeight(yMap.transform(80.0))
        pieRect.setWidth(pieRect.height())

        angle = 3 * 5760 / 4
        for key in ["User", "System", "Idle"]:
            curve = self.plot().cpuPlotCurve(key)
            if curve.dataSize():
                value = int(5760 * curve.sample(0).y() / 100.0)
                painter.save()
                painter.setBrush(QBrush(curve.pen().color(), Qt.SolidPattern))
                painter.drawPie(pieRect, -angle, -value)
                painter.restore()
                angle += value
Example #20
0
 def __init__(self, *args):
     if len(args) in (0, 1):
         if args:
             style, = args
         else:
             style = QwtSymbol.NoSymbol
         self.__data = QwtSymbol_PrivateData(style, QBrush(Qt.gray),
                                             QPen(Qt.black, 0), QSize())
     elif len(args) == 4:
         style, brush, pen, size = args
         self.__data = QwtSymbol_PrivateData(style, brush, pen, size)
     elif len(args) == 3:
         path, brush, pen = args
         self.__data = QwtSymbol_PrivateData(QwtSymbol.Path, brush, pen,
                                             QSize())
         self.setPath(path)
     else:
         raise TypeError("%s() takes 1, 3, or 4 argument(s) (%s given)"\
                         % (self.__class__.__name__, len(args)))
Example #21
0
    def __init__(self, *args):
        QwtPlot.__init__(self, *args)

        self.setCanvasBackground(Qt.white)
        self.alignScales()

        # Initialize data
        self.x = np.arange(0.0, 100.1, 0.5)
        self.y = np.zeros(len(self.x), np.float)
        self.z = np.zeros(len(self.x), np.float)

        self.setTitle("A Moving QwtPlot Demonstration")
        self.insertLegend(QwtLegend(), QwtPlot.BottomLegend);

        self.curveR = QwtPlotCurve("Data Moving Right")
        self.curveR.attach(self)
        self.curveL = QwtPlotCurve("Data Moving Left")
        self.curveL.attach(self)

        self.curveL.setSymbol(QwtSymbol(QwtSymbol.Ellipse,
                                        QBrush(),
                                        QPen(Qt.yellow),
                                        QSize(7, 7)))

        self.curveR.setPen(QPen(Qt.red))
        self.curveL.setPen(QPen(Qt.blue))

        mY = QwtPlotMarker()
        mY.setLabelAlignment(Qt.AlignRight | Qt.AlignTop)
        mY.setLineStyle(QwtPlotMarker.HLine)
        mY.setYValue(0.0)
        mY.attach(self)

        self.setAxisTitle(QwtPlot.xBottom, "Time (seconds)")
        self.setAxisTitle(QwtPlot.yLeft, "Values")
    
        self.startTimer(50)
        self.phase = 0.0
Example #22
0
 def drawRoundFrame(self, painter, rect, palette, lineWidth, frameStyle):
     Plain, Sunken, Raised = list(range(3))
     style = Plain
     if (frameStyle & QFrame.Sunken) == QFrame.Sunken:
         style = Sunken
     elif (frameStyle & QFrame.Raised) == QFrame.Raised:
         style = Raised
     lw2 = .5 * lineWidth
     r = rect.adjusted(lw2, lw2, -lw2, -lw2)
     if style != Plain:
         c1 = palette.color(QPalette.Light)
         c2 = palette.color(QPalette.Dark)
         if style == Sunken:
             c1, c2 = c2, c1
         gradient = QLinearGradient(r.topLeft(), r.bottomRight())
         gradient.setColorAt(0., c1)
         gradient.setColorAt(1., c2)
         brush = QBrush(gradient)
     else:
         brush = palette.brush(QPalette.WindowText)
     painter.save()
     painter.setPen(QPen(brush, lineWidth))
     painter.drawEllipse(r)
     painter.restore()
Example #23
0
    def __init__(self, *args):
        QwtPlot.__init__(self, *args)
        
        self.uut_dev = None
        self.timerId = None
        self.interval = 250    # ms
        
        
        fileTIME = datetime.datetime.now()
        File_timestamp = "%04d-%02d-%02d_%02d%02d%02d" % (fileTIME.year,fileTIME.month,fileTIME.day,fileTIME.hour, fileTIME.minute, fileTIME.second)

        self.fileNamme = '.\data\data_%s.txt'%File_timestamp
        print(self.fileNamme)
        self.x_range = 180.1
        self.x_interval = 10.0
        self.y_range_Upper = 210.0
        self.y_range_Lower = -90.0
        self.y_interval = 20.0
        self.unit = 'kPa'  # default value, will replaced by actual reading.
        self.getReadingCommand = r"UPPER_VAL?\r\n"  # default pass and pac
        self.getResp_rex = r'^[-]?([0-9]{1,}[.]?[0-9]*)'
                              
        self.lenth = 40 # 10s caculate the slowrate
                
        # QwtPlot property
        # Initialize 坐标轴
        self.setCanvasBackground(Qt.white)  #Qt.white
        self.alignScales()
        grid = QwtPlotGrid()
        grid.attach(self)
        grid.setMajorPen(QPen(Qt.black, 0, Qt.DotLine))
        
        self.setAxisScale(QwtPlot.xBottom, 0.0,self.x_range,self.x_interval)
        #self.setAxisAutoScale(QwtPlot.yLeft,True)
        #self.setAxisScale(QwtPlot.yLeft,99.99,100.0,0.0005)
        self.setAxisScale(QwtPlot.yLeft,self.y_range_Lower,self.y_range_Upper,self.y_interval)
        self.setAxisLabelRotation(QwtPlot.xBottom,-45.0)
        
        self.x = np.arange(0.0, self.x_range + 1, 0.25)#0.25 for ONE POINT, THIS SHOULD BE Align to the reading rate:250ms

        #self.z = np.zeros(len(self.x), np.float)
        
        list = []
        for i in range(len(self.x)):
            list.append(0.0)
        self.z = np.array(list)  
       
        rlist = []
        
        for i in range(self.lenth):  # 10s
            rlist.append(0.0)       
        self.RateList = np.array(rlist)           

        self.setTitle("UUT Reading Monitor - OutPort(%s)\r\n"%(self.unit))
        self.insertLegend(QwtLegend(), QwtPlot.RightLegend);

        
        self.curveL = QwtPlotCurve("UUT Reading")
        self.curveL.attach(self)
        pen = QPen(Qt.red)
        pen.setWidth(1.5)
        self.curveL.setPen(pen)
        
        # show peak line and point value
        fn = self.fontInfo().family()
        self.peakMarker = m = QwtPlotMarker()
        m.setLineStyle(QwtPlotMarker.HLine)
        m.setLabelAlignment(Qt.AlignLeft | Qt.AlignTop)
        m.setLinePen(QPen(Qt.blue, 1.5, Qt.DashDotLine))
        
        text = QwtText('dfdfdfdf')
        text.setColor(Qt.red)
        text.setBackgroundBrush(QBrush(self.canvasBackground()))
        text.setFont(QFont(fn, 12, QFont.Bold))         
        m.setLabel(text)
        # MarkPoint symbol
        m.setSymbol(QwtSymbol(QwtSymbol.Diamond,
                              QBrush(Qt.blue),
                              QPen(Qt.green),
                              QSize(7,7)))
        m.attach(self)
        
        # text marker
        self.txtMarker = m = QwtPlotMarker()
        m.setValue(self.x_range/2, self.y_range_Upper - self.y_interval/2)   # show position
        m.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom)
        text = QwtText('initial')
        text.setFont(QFont(fn, 20, QFont.Bold))
        text.setColor(Qt.white)
        text.setBackgroundBrush(QBrush(Qt.black))
        text.setBorderPen(QPen(Qt.red, 2))

        m.setLabel(text)
        m.attach(self)
        

        self.setAxisTitle(QwtPlot.xBottom, "Time (seconds)")
        self.setAxisTitle(QwtPlot.yLeft, "UUT - Reading(%s)"%(self.unit))
        self.replot()
 
        #self.startTimer(250)#ms# FOR GET READING
        
        self.starttime = time.clock();#unit: s
        self.idx = 0
        self.readfmt = "%f" 
        self.Saveinfo("Starting...")
Example #24
0
 def __init__(self):
     self.brush = QBrush()
     self.origin = QPointF()
Example #25
0
 def __init__(self):
     self.path = QPainterPath()
     self.brush = QBrush()
     self.origin = QPointF()
    def __init__(self, *args):
        QwtPlot.__init__(self, *args)

        self.uut_dev = None
        self.timerId = None
        #self.interval = 250    # ms
        self.interval = config.interval  # ms

        fileTIME = datetime.datetime.now()
        File_timestamp = "%04d-%02d-%02d_%02d%02d%02d" % (
            fileTIME.year, fileTIME.month, fileTIME.day, fileTIME.hour,
            fileTIME.minute, fileTIME.second)

        self.fileNamme = '.\data\data_%s.txt' % File_timestamp
        print('Raw data record file name:%s' % self.fileNamme)
        # default parameters from config file
        self.x_ZERO = config.X_lower
        self.x_range = config.X_upper
        self.x_interval = config.X_grid_interval
        self.y_range_Upper = config.Y_upper
        self.y_range_Lower = config.Y_lower
        self.y_interval = config.Y_grid_interval
        self.unit = 'kPa'  # default value, will replaced by actual reading.
        #self.getReadingCommand = r"UPPER_VAL?\r\n"  # default pass and pac
        #self.getResp_rex = r'^[-]?([0-9]{1,}[.]?[0-9]*)'

        self.lenth = config.Slope_lenth  #  40 = 10s caculate the slowrate

        # QwtPlot property
        # Initialize 坐标轴
        self.setCanvasBackground(Qt.white)  #Qt.white
        self.alignScales()
        grid = QwtPlotGrid()
        grid.attach(self)
        grid.setMajorPen(QPen(Qt.black, 0, Qt.DotLine))

        # x Axis property
        #self.setAxisScaleDraw(QwtPlot.xBottom, TimeScaleDraw(self.cpuStat.upTime()))
        #timeScale = QwtDateScaleDraw(Qt.LocalTime)
        #print(timeScale)
        #self.setAxisScaleDraw(QwtPlot.xBottom, timeScale)

        self.setAxisScale(QwtPlot.xBottom, 0.0, self.x_range, self.x_interval)

        #self.setAxisAutoScale(QwtPlot.yLeft,True)
        #self.setAxisScale(QwtPlot.yLeft,99.99,100.0,0.0005)
        self.setAxisScale(QwtPlot.yLeft, self.y_range_Lower,
                          self.y_range_Upper, self.y_interval)
        self.setAxisLabelRotation(QwtPlot.xBottom, -45.0)

        self.x = np.arange(
            0.0, self.x_range + 1, 0.25
        )  #0.25 for ONE POINT, THIS SHOULD BE Align to the reading rate:250ms

        #self.z = np.zeros(len(self.x), np.float)
        list = []
        for i in range(len(self.x)):
            list.append(0.0)
        self.z = np.array(list)

        rlist = []

        for i in range(self.lenth):  # 10s
            rlist.append(0.0)
        self.RateList = np.array(rlist)

        self.setTitle("UUT Reading Monitor - OutPort(%s)\r\n" % (self.unit))
        #self.insertLegend(QwtLegend(), QwtPlot.RightLegend);

        self.curveL = QwtPlotCurve("UUT Reading")
        self.curveL.attach(self)
        pen = QPen(Qt.red)
        pen.setWidth(1.5)
        #pen.setWidth(1)
        self.curveL.setPen(pen)

        font = QFont()
        font.setFamily("Calibri")  #,Consolas
        font.setPointSize(16)

        # show the latest reading. line and point value
        self.peakMarker = m = QwtPlotMarker()
        m.setLineStyle(QwtPlotMarker.HLine)
        m.setLabelAlignment(Qt.AlignLeft | Qt.AlignTop)
        m.setLinePen(QPen(Qt.blue, 1.5, Qt.DashDotLine))

        text = QwtText('Reading: ----')
        text.setColor(Qt.red)
        text.setBackgroundBrush(QBrush(self.canvasBackground()))

        text.setFont(font)

        m.setLabel(text)
        # MarkPoint symbol
        m.setSymbol(
            QwtSymbol(QwtSymbol.Diamond, QBrush(Qt.blue), QPen(Qt.green),
                      QSize(7, 7)))
        m.attach(self)

        # text marker  , display slope rate
        self.txtMarker = m = QwtPlotMarker()
        m.setValue(self.x_range / 2,
                   self.y_range_Upper - self.y_interval / 2)  # show position
        m.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom)
        text = QwtText('Slope Rate: ----')
        text.setFont(font)
        text.setColor(Qt.white)
        text.setBackgroundBrush(QBrush(Qt.black))
        text.setBorderPen(QPen(Qt.red, 2))

        m.setLabel(text)
        m.attach(self)

        self.setAxisTitle(QwtPlot.xBottom, "Time (seconds)")
        self.setAxisTitle(QwtPlot.yLeft, "UUT - Reading(%s)" % (self.unit))

        self.replot()

        #self.startTimer(250)#ms# FOR GET READING
        #self.starttime = time.clock();#unit: s    python2
        self.starttime = time.time()  # python3

        self.idx = 0
        self.readfmt = "%f"
        self.Saveinfo("Starting...")
Example #27
0
 def __init__(self):
     self.baseline = 0.
     self.style = 0
     self.symbol = None
     self.pen = QPen()
     self.brush = QBrush()
Example #28
0
    def __init__(self, *args):
        QwtPlot.__init__(self, *args)

        self.setTitle('Frequency Response of a 2<sup>nd</sup>-order System')
        self.setCanvasBackground(Qt.darkBlue)

        # legend
        legend = QwtLegend()
        legend.setFrameStyle(QFrame.Box | QFrame.Sunken)
        self.insertLegend(legend, QwtPlot.BottomLegend)

        # grid
        self.grid = QwtPlotGrid()
        self.grid.enableXMin(True)
        self.grid.attach(self)

        # axes
        self.enableAxis(QwtPlot.yRight)
        self.setAxisTitle(QwtPlot.xBottom, '\u03c9/\u03c9<sub>0</sub>')
        self.setAxisTitle(QwtPlot.yLeft, 'Amplitude [dB]')
        self.setAxisTitle(QwtPlot.yRight, 'Phase [\u00b0]')

        self.setAxisMaxMajor(QwtPlot.xBottom, 6)
        self.setAxisMaxMinor(QwtPlot.xBottom, 10)
        self.setAxisScaleEngine(QwtPlot.xBottom, QwtLogScaleEngine())

        # curves
        self.curve1 = QwtPlotCurve('Amplitude')
        self.curve1.setRenderHint(QwtPlotItem.RenderAntialiased)
        self.curve1.setPen(QPen(Qt.yellow))
        self.curve1.setYAxis(QwtPlot.yLeft)
        self.curve1.attach(self)

        self.curve2 = QwtPlotCurve('Phase')
        self.curve2.setRenderHint(QwtPlotItem.RenderAntialiased)
        self.curve2.setPen(QPen(Qt.cyan))
        self.curve2.setYAxis(QwtPlot.yRight)
        self.curve2.attach(self)

        # alias
        fn = self.fontInfo().family()

        # marker
        self.dB3Marker = m = QwtPlotMarker()
        m.setValue(0.0, 0.0)
        m.setLineStyle(QwtPlotMarker.VLine)
        m.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom)
        m.setLinePen(QPen(Qt.green, 2, Qt.DashDotLine))
        text = QwtText('')
        text.setColor(Qt.green)
        text.setBackgroundBrush(Qt.red)
        text.setFont(QFont(fn, 12, QFont.Bold))
        m.setLabel(text)
        m.attach(self)

        self.peakMarker = m = QwtPlotMarker()
        m.setLineStyle(QwtPlotMarker.HLine)
        m.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom)
        m.setLinePen(QPen(Qt.red, 2, Qt.DashDotLine))
        text = QwtText('')
        text.setColor(Qt.red)
        text.setBackgroundBrush(QBrush(self.canvasBackground()))
        text.setFont(QFont(fn, 12, QFont.Bold))

        m.setLabel(text)
        m.setSymbol(
            QwtSymbol(QwtSymbol.Diamond, QBrush(Qt.yellow), QPen(Qt.green),
                      QSize(7, 7)))
        m.attach(self)

        # text marker
        m = QwtPlotMarker()
        m.setValue(0.1, -20.0)
        m.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom)
        text = QwtText('[1-(\u03c9/\u03c9<sub>0</sub>)<sup>2</sup>+2j\u03c9/Q]'
                       '<sup>-1</sup>')
        text.setFont(QFont(fn, 12, QFont.Bold))
        text.setColor(Qt.blue)
        text.setBackgroundBrush(QBrush(Qt.yellow))
        text.setBorderPen(QPen(Qt.red, 2))
        m.setLabel(text)
        m.attach(self)

        self.setDamp(0.01)