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)
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)
def qwtScaleBoundingRect(graphic, size): scaledSize = QSize(size) if scaledSize.isEmpty(): scaledSize = graphic.defaultSize() sz = graphic.controlPointRect().size() sx = 1. if sz.width() > 0.: sx = scaledSize.width() / sz.width() sy = 1. if sz.height() > 0.: sy = scaledSize.height() / sz.height() return graphic.scaledBoundingRect(sx, sy)
def qwtScaleBoundingRect(graphic, size): scaledSize = QSize(size) if scaledSize.isEmpty(): scaledSize = graphic.defaultSize() sz = graphic.controlPointRect().size() sx = 1. if sz.width() > 0.: sx = scaledSize.width()/sz.width() sy = 1. if sz.height() > 0.: sy = scaledSize.height()/sz.height() return graphic.scaledBoundingRect(sx, sy)
def setSize(self, *args): """ Specify the symbol's size .. py:method:: setSize(width, [height=-1]) :param int width: Width :param int height: Height .. py:method:: setSize(size) :param QSize size: Size .. seealso:: :py:meth:`size()` """ if len(args) == 2: width, height = args if width >= 0 and height < 0: height = width self.setSize(QSize(width, height)) elif len(args) == 1: if isinstance(args[0], QSize): size, = args if size.isValid() and size != self.__data.size: self.__data.size = size self.invalidateCache() else: width, = args self.setSize(width, -1) else: raise TypeError("%s().setSize() takes 1 or 2 argument(s) (%s given)"\ % (self.__class__.__name__, len(args)))
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
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()
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()
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
def sizeHint(self): if self.isEmpty(): return QSize() numColumns = self.itemCount() if self.__data.maxColumns > 0: numColumns = min([self.__data.maxColumns, numColumns]) numRows = int(self.itemCount() / numColumns) if self.itemCount() % numColumns: numRows += 1 rowHeight = [0] * numRows colWidth = [0] * numColumns self.layoutGrid(numColumns, rowHeight, colWidth) margins = self.contentsMargins() margin_h = margins.top() + margins.bottom() margin_w = margins.left() + margins.right() h = margin_h + (numRows - 1) * self.spacing() + sum(rowHeight) w = margin_w + (numColumns - 1) * self.spacing() + sum(colWidth) return QSize(w, h)
def qwtScreenResolution(): screenResolution = QSize() if not screenResolution.isValid(): desktop = QApplication.desktop() if desktop is not None: screenResolution.setWidth(desktop.logicalDpiX()) screenResolution.setHeight(desktop.logicalDpiY()) return screenResolution
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)
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)))
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)
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), )
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)
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
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)
def viewportSize(self, w, h): sbHeight = self.horizontalScrollBar().sizeHint().height() sbWidth = self.verticalScrollBar().sizeHint().width() cw = self.contentsRect().width() ch = self.contentsRect().height() vw = cw vh = ch if w > vw: vh -= sbHeight if h > vh: vw -= sbWidth if w > vw and vh == ch: vh -= sbHeight return QSize(vw, vh)
def sizeHint(self): """ Return the size hint. If maxColumns() > 0 it is the size for a grid with maxColumns() columns, otherwise it is the size for a grid with only one row. """ if self.isEmpty(): return QSize() numColumns = self.itemCount() if self.__data.maxColumns > 0: numColumns = min([self.__data.maxColumns, numColumns]) numRows = int(self.itemCount()/numColumns) if self.itemCount() % numColumns: numRows += 1 rowHeight = [0] * numRows colWidth = [0] * numColumns self.layoutGrid(numColumns, rowHeight, colWidth) margins = self.contentsMargins() margin_h = margins.top() + margins.bottom() margin_w = margins.left() + margins.right() h = margin_h+(numRows-1)*self.spacing()+sum(rowHeight) w = margin_w+(numColumns-1)*self.spacing()+sum(colWidth) return QSize(w, h)
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)))
def minimumSizeHint(self): sz = self.__data.text.textSize(self.font()) mw = 2 * (self.frameWidth() + self.__data.margin) mh = mw indent = self.__data.indent if indent <= 0: indent = self.defaultIndent() if indent > 0: align = self.__data.text.renderFlags() if align & Qt.AlignLeft or align & Qt.AlignRight: mw += self.__data.indent elif align & Qt.AlignTop or align & Qt.AlignBottom: mh += self.__data.indent sz += QSizeF(mw, mh) return QSize(np.ceil(sz.width()), np.ceil(sz.height()))
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)
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)
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
def __init__(self): self.frameWidth = None self.hScrollExtent = None self.vScrollExtent = None self.hint = QSize()
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)
def buttonShift(w): option = QStyleOption() option.initFrom(w) ph = w.style().pixelMetric(QStyle.PM_ButtonShiftHorizontal, option, w) pv = w.style().pixelMetric(QStyle.PM_ButtonShiftVertical, option, w) return QSize(ph, pv)
def minimumSizeHint(self, plot): class _ScaleData(object): def __init__(self): self.w = 0 self.h = 0 self.minLeft = 0 self.minRight = 0 self.tickOffset = 0 scaleData = [_ScaleData() for _i in range(QwtPlot.axisCnt)] canvasBorder = [0 for _i in range(QwtPlot.axisCnt)] fw, _, _, _ = plot.canvas().getContentsMargins() for axis in range(QwtPlot.axisCnt): if plot.axisEnabled(axis): scl = plot.axisWidget(axis) sd = scaleData[axis] hint = scl.minimumSizeHint() sd.w = hint.width() sd.h = hint.height() sd.minLeft, sd.minLeft = scl.getBorderDistHint() sd.tickOffset = scl.margin() if scl.scaleDraw().hasComponent(QwtAbstractScaleDraw.Ticks): sd.tickOffset += np.ceil(scl.scaleDraw().maxTickLength()) canvasBorder[axis] = fw + self.__data.canvasMargin[axis] + 1 for axis in range(QwtPlot.axisCnt): sd = scaleData[axis] if sd.w and axis in (QwtPlot.xBottom, QwtPlot.xTop): if sd.minLeft > canvasBorder[QwtPlot.yLeft]\ and scaleData[QwtPlot.yLeft].w: shiftLeft = sd.minLeft - canvasBorder[QwtPlot.yLeft] if shiftLeft > scaleData[QwtPlot.yLeft].w: shiftLeft = scaleData[QwtPlot.yLeft].w sd.w -= shiftLeft if sd.minRight > canvasBorder[QwtPlot.yRight]\ and scaleData[QwtPlot.yRight].w: shiftRight = sd.minRight - canvasBorder[QwtPlot.yRight] if shiftRight > scaleData[QwtPlot.yRight].w: shiftRight = scaleData[QwtPlot.yRight].w sd.w -= shiftRight if sd.h and axis in (QwtPlot.yLeft, QwtPlot.yRight): if sd.minLeft > canvasBorder[QwtPlot.xBottom]\ and scaleData[QwtPlot.xBottom].h: shiftBottom = sd.minLeft - canvasBorder[QwtPlot.xBottom] if shiftBottom > scaleData[QwtPlot.xBottom].tickOffset: shiftBottom = scaleData[QwtPlot.xBottom].tickOffset sd.h -= shiftBottom if sd.minLeft > canvasBorder[QwtPlot.xTop]\ and scaleData[QwtPlot.xTop].h: shiftTop = sd.minRight - canvasBorder[QwtPlot.xTop] if shiftTop > scaleData[QwtPlot.xTop].tickOffset: shiftTop = scaleData[QwtPlot.xTop].tickOffset sd.h -= shiftTop canvas = plot.canvas() left, top, right, bottom = canvas.getContentsMargins() minCanvasSize = canvas.minimumSize() w = scaleData[QwtPlot.yLeft].w + scaleData[QwtPlot.yRight].w cw = max([scaleData[QwtPlot.xBottom].w, scaleData[QwtPlot.xTop].w ]) + left + 1 + right + 1 w += max([cw, minCanvasSize.width()]) h = scaleData[QwtPlot.xBottom].h + scaleData[QwtPlot.xTop].h ch = max([scaleData[QwtPlot.yLeft].h, scaleData[QwtPlot.yRight].h ]) + top + 1 + bottom + 1 h += max([ch, minCanvasSize.height()]) for label in [plot.titleLabel(), plot.footerLabel()]: if label and not label.text().isEmpty(): centerOnCanvas = not plot.axisEnabled(QwtPlot.yLeft)\ and plot.axisEnabled(QwtPlot.yRight) labelW = w if centerOnCanvas: labelW -= scaleData[QwtPlot.yLeft].w +\ scaleData[QwtPlot.yRight].w labelH = label.heightForWidth(labelW) if labelH > labelW: w = labelW = labelH if centerOnCanvas: w += scaleData[QwtPlot.yLeft].w +\ scaleData[QwtPlot.yRight].w labelH = label.heightForWidth(labelW) h += labelH + self.__data.spacing legend = plot.legend() if legend and not legend.isEmpty(): if self.__data.legendPos in (QwtPlot.LeftLegend, QwtPlot.RightLegend): legendW = legend.sizeHint().width() legendH = legend.heightForWidth(legendW) if legend.frameWidth() > 0: w += self.__data.spacing if legendH > h: legendW += legend.scrollExtent(Qt.Horizontal) if self.__data.legendRatio < 1.: legendW = min( [legendW, int(w / (1. - self.__data.legendRatio))]) w += legendW + self.__data.spacing else: legendW = min([legend.sizeHint().width(), w]) legendH = legend.heightForWidth(legendW) if legend.frameWidth() > 0: h += self.__data.spacing if self.__data.legendRatio < 1.: legendH = min( [legendH, int(h / (1. - self.__data.legendRatio))]) h += legendH + self.__data.spacing return QSize(w, h)
def sizeHint(self): """Return a size hint""" hint = self.__data.view.contentsWidget.sizeHint() hint += QSize(2*self.frameWidth(), 2*self.frameWidth()) return hint
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...")