def populate(self): #Insert new curves self.cSin = Qwt.QwtPlotCurve("y = sin(x)") self.cSin.setRenderHint(Qwt.QwtPlotItem.RenderAntialiased) self.cSin.setLegendAttribute(Qwt.QwtPlotCurve.LegendShowLine, True) self.cSin.setPen(Qt.red) self.cSin.attach(self) self.cCos = Qwt.QwtPlotCurve("y = cos(x)") self.cCos.setRenderHint(Qwt.QwtPlotItem.RenderAntialiased) self.cCos.setLegendAttribute(Qwt.QwtPlotCurve.LegendShowLine, True) self.cCos.setPen(Qt.blue) self.cCos.attach(self) #Create sin and cos data self.s = FunctionData(sin) self.cSin.setData(self.s) self.c = FunctionData(cos) self.cCos.setData(self.c) #Insert markers # ...a horizontal line at y = 0... self.mY = Qwt.QwtPlotMarker() self.mY.setLabel(Qwt.QwtText("y = 0")) self.mY.setLabelAlignment(Qt.AlignRight | Qt.AlignTop) self.mY.setLineStyle(Qwt.QwtPlotMarker.HLine) self.mY.setYValue(0.0) self.mY.attach(self) # ...a vertical line at x = 2 * pi self.mX = Qwt.QwtPlotMarker() self.mX.setLabel(Qwt.QwtText("x = 2 pi")) self.mX.setLabelAlignment(Qt.AlignLeft | Qt.AlignBottom) self.mX.setLabelOrientation(Qt.Vertical) self.mX.setLineStyle(Qwt.QwtPlotMarker.VLine) self.mX.setLinePen(Qt.black, 0, Qt.DashDotLine) self.mX.setXValue(2.0 * pi) self.mX.attach(self) x = 7.7 # an arrow at a specific position self.mPos = Qwt.QwtPlotMarker("Marker") self.mPos.setRenderHint(Qwt.QwtPlotItem.RenderAntialiased, True) self.mPos.setItemAttribute(Qwt.QwtPlotItem.Legend, True) self.arr = ArrowSymbol() self.mPos.setSymbol(self.arr) self.mPos.setValue(QPointF(x, sin(x))) self.mPos.setLabel(Qwt.QwtText("x = %.1f" % x)) self.mPos.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom) self.mPos.attach(self)
def show3dB(self, freq): label = "-3 dB at f = %.3g" % freq text = Qwt.QwtText(label) text.setFont(QFont("Helvetica", 10, QFont.Bold)) text.setColor(Qt.green) self.d_marker1.setValue(freq, 0.0) self.d_marker1.setLabel(text)
def showPeak(self, freq, amplitude): label = "Peak: %.3g dB" % amplitude text = Qwt.QwtText(label) text.setFont(QFont("Helvetica", 10, QFont.Bold)) text.setColor(QColor(200, 150, 0)) self.d_marker2.setValue(freq, amplitude) self.d_marker2.setLabel(text)
def populate(self): colors = [colours["DarkOrchid"], colours["SteelBlue"], colours["Gold"]] numSamples = 5 numBars = len(colors) titles = [] for i in range(numBars): titles.append(Qwt.QwtText("Bar %d" % i)) self.d_barChartItem.setBarTitles(titles) self.d_barChartItem.setLegendIconSize(QSize(10, 14)) for i in range(numBars): symbol = Qwt.QwtColumnSymbol(Qwt.QwtColumnSymbol.Box) symbol.setLineWidth(2) symbol.setFrameStyle(Qwt.QwtColumnSymbol.Raised) symbol.setPalette(QPalette(colors[i])) self.d_barChartItem.setSymbol(i, symbol) self.series = [] for i in range(numSamples): values = [] for j in range(numBars): values.append(2.0 + random.randint(0, 8) % 8) self.series.append(values) print(self.series) self.d_barChartItem.setSamples(self.series)