Esempio n. 1
0
 def init(self, plot, rect):
     """Extract all layout relevant data from the plot components"""
     # legend
     if plot.legend():
         self.legend.frameWidth = plot.legend().frameWidth()
         self.legend.hScrollExtent = plot.legend().scrollExtent(Qt.Horizontal)
         self.legend.vScrollExtent = plot.legend().scrollExtent(Qt.Vertical)
         hint = plot.legend().sizeHint()
         w = min([hint.width(), np.floor(rect.width())])
         h = plot.legend().heightForWidth(w)
         if h <= 0:
             h = hint.height()
         if h > rect.height():
             w += self.legend.hScrollExtent
         self.legend.hint = QSize(w, h)
     # title
     self.title.frameWidth = 0
     self.title.text = QwtText()
     if plot.titleLabel():
         label = plot.titleLabel()
         self.title.text = label.text()
         if not self.title.text.testPaintAttribute(QwtText.PaintUsingTextFont):
             self.title.text.setFont(label.font())
         self.title.frameWidth = plot.titleLabel().frameWidth()
     # footer
     self.footer.frameWidth = 0
     self.footer.text = QwtText()
     if plot.footerLabel():
         label = plot.footerLabel()
         self.footer.text = label.text()
         if not self.footer.text.testPaintAttribute(QwtText.PaintUsingTextFont):
             self.footer.text.setFont(label.font())
         self.footer.frameWidth = plot.footerLabel().frameWidth()
     # scales
     for axis in QwtPlot.validAxes:
         if plot.axisEnabled(axis):
             scaleWidget = plot.axisWidget(axis)
             self.scale[axis].isEnabled = True
             self.scale[axis].scaleWidget = scaleWidget
             self.scale[axis].scaleFont = scaleWidget.font()
             self.scale[axis].start = scaleWidget.startBorderDist()
             self.scale[axis].end = scaleWidget.endBorderDist()
             self.scale[axis].baseLineOffset = scaleWidget.margin()
             self.scale[axis].tickOffset = scaleWidget.margin()
             if scaleWidget.scaleDraw().hasComponent(QwtAbstractScaleDraw.Ticks):
                 self.scale[axis].tickOffset += scaleWidget.scaleDraw().maxTickLength()
             self.scale[axis].dimWithoutTitle = scaleWidget.dimForLength(
                             QWIDGETSIZE_MAX, self.scale[axis].scaleFont)
             if not scaleWidget.title().isEmpty():
                 self.scale[axis].dimWithoutTitle -= \
                         scaleWidget.titleHeightForWidth(QWIDGETSIZE_MAX)
         else:
             self.scale[axis].isEnabled = False
             self.scale[axis].start = 0
             self.scale[axis].end = 0
             self.scale[axis].baseLineOffset = 0
             self.scale[axis].tickOffset = 0.
             self.scale[axis].dimWithoutTitle = 0
     self.canvas.contentsMargins = plot.canvas().getContentsMargins()
Esempio n. 2
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
Esempio n. 3
0
    def minimumSizeHint(self):
        o = self.__data.scaleDraw.orientation()
        length = 0
        mbd1, mbd2 = self.getBorderDistHint()
        length += max([0, self.__data.borderDist[0] - mbd1])
        length += max([0, self.__data.borderDist[1] - mbd2])
        length += self.__data.scaleDraw.minLength(self.font())

        dim = self.dimForLength(length, self.font())
        if length < dim:
            length = dim
            dim = self.dimForLength(length, self.font())

        size = QSize(length + 2, dim)
        if o == Qt.Vertical:
            size.transpose()

        left, right, top, bottom = self.getContentsMargins()
        return size + QSize(left + right, top + bottom)
Esempio n. 4
0
def qwtUpdateLegendIconSize(curve):
    if curve.symbol() and\
       curve.testLegendAttribute(QwtPlotCurve.LegendShowSymbol):
        sz = curve.symbol().boundingRect().size()
        sz += QSize(2, 2)
        if curve.testLegendAttribute(QwtPlotCurve.LegendShowLine):
            w = np.ceil(1.5 * sz.width())
            if w % 2:
                w += 1
            sz.setWidth(max([8, w]))
        curve.setLegendIconSize(sz)
Esempio n. 5
0
 def __init__(self):
     self.plot = None
     self.isVisible = True
     self.attributes = 0
     self.interests = 0
     self.renderHints = 0
     self.renderThreadCount = 1
     self.z = 0.
     self.xAxis = QwtPlot.xBottom
     self.yAxis = QwtPlot.yLeft
     self.legendIconSize = QSize(8, 8)
     self.title = None # QwtText
Esempio n. 6
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)
Esempio n. 7
0
 def setSize(self, *args):
     if len(args) == 2:
         width, height = args
         if width >= 0 and height < 0:
             height = width
         self.setSize(QSize(width, height))
     elif len(args) == 1:
         size, = args
         if size.isValid() and size != self.__data.size:
             self.__data.size = size
             self.invalidateCache()
     else:
         raise TypeError("%s().setSize() takes 1 or 2 argument(s) (%s given)"\
                         % (self.__class__.__name__, len(args)))
Esempio n. 8
0
 def sizeHint(self):
     dw = dh = 0
     for axisId in range(self.axisCnt):
         if self.axisEnabled(axisId):
             niceDist = 40
             scaleWidget = self.axisWidget(axisId)
             scaleDiv = scaleWidget.scaleDraw().scaleDiv()
             majCnt = len(scaleDiv.ticks(QwtScaleDiv.MajorTick))
             if axisId in (self.yLeft, self.yRight):
                 hDiff = (majCnt-1)*niceDist-scaleWidget.minimumSizeHint().height()
                 if hDiff > dh:
                     dh = hDiff
             else:
                 wDiff = (majCnt-1)*niceDist-scaleWidget.minimumSizeHint().width()
                 if wDiff > dw:
                     dw = wDiff
     return self.minimumSizeHint() + QSize(dw, dh)
Esempio n. 9
0
 def drawSymbols(self, painter, symbol, xMap, yMap, canvasRect, from_, to):
     if self.symbolList is None and self.symbolSizes is None:
         print(
             'QwtPlotCurveSizes fail: you must specify a symbol list or an array of symbol sizes'
         )
         return
     painter.setBrush(symbol.brush())
     painter.setPen(symbol.pen())
     for i in range(from_, to + 1):
         if not self.symbolList is None:
             painter.setBrush(self.symbolList[i].brush())
             painter.setPen(self.symbolList[i].pen())
         xi = xMap.transform(self.__x[i])
         yi = yMap.transform(self.__y[i])
         position = QPointF(float(xi), float(yi))
         if not self.symbolList is None:
             self.symbolList[i].drawSymbol(painter, position)
         else:
             symbol.setSize(QSize(self.symbolSizes[i], self.symbolSizes[i]))
             symbol.drawSymbol(painter, position)
    def __init__(self, buffersize=0, parent=None, name=None, modal=True, fl=0):
        QDialog.__init__(self, parent)

        self.setModal(modal)

        BufferSizeDialogLayout = QVBoxLayout(self)

        layout1 = QHBoxLayout(None)

        self.label = QLabel(self)
        layout1.addWidget(self.label)

        self.spinBox1 = QSpinBox(self)
        self.spinBox1.setMinimum(0)
        self.spinBox1.setWrapping(True)
        self.spinBox1.setValue(buffersize)
        self.value = buffersize

        layout1.addWidget(self.spinBox1)
        BufferSizeDialogLayout.addLayout(layout1)

        layout3 = QHBoxLayout(None)
        spacer1 = QSpacerItem(71, 31, QSizePolicy.Expanding,
                              QSizePolicy.Minimum)
        layout3.addItem(spacer1)

        self.okButton = QPushButton("okButton", self)
        layout3.addWidget(self.okButton)

        self.cancelButton = QPushButton("cancelButton", self)
        layout3.addWidget(self.cancelButton)
        BufferSizeDialogLayout.addLayout(layout3)

        self.resize(QSize(267, 84).expandedTo(self.minimumSizeHint()))

        self.okButton.clicked.connect(self.runDone)
        self.cancelButton.clicked.connect(self.runCancel)
        self.spinBox1.valueChanged.connect(self.updateValue)

        self.label.setBuddy(self.spinBox1)
Esempio n. 11
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)