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 __init__(self,parent): super().__init__(parent) self.__d_interval = Qwt.QwtInterval( 0.0, 10.0 ) self.__d_timerId = -1 self.__d_directPainter = Qwt.QwtPlotDirectPainter() self.__d_clock = Qwt.QwtSystemClock() self.__d_paintedPoints = 0 self.setAutoReplot( False ) self.setCanvas( Canvas() ) self.plotLayout().setAlignCanvasToScales( True ) self.setAxisTitle( Qwt.QwtPlot.xBottom, "Time [s]" ) self.setAxisScale( Qwt.QwtPlot.xBottom, self.__d_interval.minValue(), self.__d_interval.maxValue() ) self.setAxisScale( Qwt.QwtPlot.yLeft, -200.0, 200.0 ) self.grid = Qwt.QwtPlotGrid() self.grid.setPen( Qt.gray, 0.0, Qt.DotLine ) self.grid.enableX( True ) self.grid.enableXMin( True ) self.grid.enableY( True ) self.grid.enableYMin( False ) self.grid.attach( self ) self.__d_origin = Qwt.QwtPlotMarker() self.__d_origin.setLineStyle( Qwt.QwtPlotMarker.Cross ) self.__d_origin.setValue( self.__d_interval.minValue() + self.__d_interval.width() / 2.0, 0.0 ) self.__d_origin.setLinePen( Qt.gray, 0.0, Qt.DashLine ) self.__d_origin.attach( self ) self.__d_curve = Qwt.QwtPlotCurve() self.__d_curve.setStyle( Qwt.QwtPlotCurve.Lines ) self.__d_curve.setPen( self.canvas().palette().color( QPalette.WindowText ) ) self.__d_curve.setRenderHint( Qwt.QwtPlotItem.RenderAntialiased, True ) self.__d_curve.setPaintAttribute( Qwt.QwtPlotCurve.ClipPolygons, False ) self.__cdata = CurveData() self.__d_curve.setData( self.__cdata ) self.__d_curve.attach( self )
def __init__(self, parent=None): Qwt.QwtPlot.__init__(self, parent) self.setAutoReplot(False) self.setTitle("Frequency Response of a Second-Order System") canvas = Qwt.QwtPlotCanvas() canvas.setBorderRadius(10) self.setCanvas(canvas) self.setCanvasBackground(QColor("MidnightBlue")) # legend legend = Qwt.QwtLegend() self.insertLegend(legend, Qwt.QwtPlot.BottomLegend) # grid grid = Qwt.QwtPlotGrid() grid.enableXMin(True) grid.setMajorPen(Qt.white, 0, Qt.DotLine) grid.setMinorPen(Qt.gray, 0, Qt.DotLine) grid.attach(self) # axes self.enableAxis(Qwt.QwtPlot.yRight) self.setAxisTitle(Qwt.QwtPlot.xBottom, "Normalized Frequency") self.setAxisTitle(Qwt.QwtPlot.yLeft, "Amplitude [dB]") self.setAxisTitle(Qwt.QwtPlot.yRight, "Phase [deg]") self.setAxisMaxMajor(Qwt.QwtPlot.xBottom, 6) self.setAxisMaxMinor(Qwt.QwtPlot.xBottom, 9) self.setAxisScaleEngine(Qwt.QwtPlot.xBottom, Qwt.QwtLogScaleEngine()) # curves self.d_curve1 = Qwt.QwtPlotCurve("Amplitude") self.d_curve1.setRenderHint(Qwt.QwtPlotItem.RenderAntialiased) self.d_curve1.setPen(Qt.yellow) self.d_curve1.setLegendAttribute(Qwt.QwtPlotCurve.LegendShowLine) self.d_curve1.setYAxis(Qwt.QwtPlot.yLeft) self.d_curve1.attach(self) self.d_curve2 = Qwt.QwtPlotCurve("Phase") self.d_curve2.setRenderHint(Qwt.QwtPlotItem.RenderAntialiased) self.d_curve2.setPen(Qt.cyan) self.d_curve2.setLegendAttribute(Qwt.QwtPlotCurve.LegendShowLine) self.d_curve2.setYAxis(Qwt.QwtPlot.yRight) self.d_curve2.attach(self) # marker self.d_marker1 = Qwt.QwtPlotMarker() self.d_marker1.setValue(0.0, 0.0) self.d_marker1.setLineStyle(Qwt.QwtPlotMarker.VLine) self.d_marker1.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom) self.d_marker1.setLinePen(Qt.green, 0, Qt.DashDotLine) self.d_marker1.attach(self) self.d_marker2 = Qwt.QwtPlotMarker() self.d_marker2.setLineStyle(Qwt.QwtPlotMarker.HLine) self.d_marker2.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom) self.d_marker2.setLinePen(QColor(200, 150, 0), 0, Qt.DashDotLine) self.d_marker2.setSymbol( Qwt.QwtSymbol(Qwt.QwtSymbol.Diamond, QColor(Qt.yellow), QColor(Qt.green), QSize(8, 8))) self.d_marker2.attach(self) self.setDamp(0) self.setAutoReplot(True)