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, *args): QwtPlot.__init__(self, *args) self.setTitle('ReallySimpleDemo.py') self.insertLegend(QwtLegend(), QwtPlot.RightLegend) self.setAxisTitle(QwtPlot.xBottom, 'x -->') self.setAxisTitle(QwtPlot.yLeft, 'y -->') self.enableAxis(self.xBottom) # insert a few curves cSin = QwtPlotCurve('y = sin(x)') cSin.setPen(QPen(Qt.red)) cSin.attach(self) cCos = QwtPlotCurve('y = cos(x)') cCos.setPen(QPen(Qt.blue)) cCos.attach(self) # make a Numeric array for the horizontal data x = np.arange(0.0, 10.0, 0.1) # initialize the data cSin.setData(x, np.sin(x)) cCos.setData(x, np.cos(x)) # insert a horizontal marker at y = 0 mY = QwtPlotMarker() mY.setLabel(QwtText('y = 0')) mY.setLabelAlignment(Qt.AlignRight | Qt.AlignTop) mY.setLineStyle(QwtPlotMarker.HLine) mY.setYValue(0.0) mY.attach(self) # insert a vertical marker at x = 2 pi mX = QwtPlotMarker() mX.setLabel(QwtText('x = 2 pi')) mX.setLabelAlignment(Qt.AlignRight | Qt.AlignTop) mX.setLineStyle(QwtPlotMarker.VLine) mX.setXValue(2*np.pi) mX.attach(self) # replot self.replot()
def __init__(self, *args): QwtPlot.__init__(self, *args) self.setTitle('ReallySimpleDemo.py') self.insertLegend(QwtLegend(), QwtPlot.RightLegend) self.setAxisTitle(QwtPlot.xBottom, 'x -->') self.setAxisTitle(QwtPlot.yLeft, 'y -->') self.enableAxis(self.xBottom) # insert a few curves cSin = QwtPlotCurve('y = sin(x)') cSin.setPen(QPen(Qt.red)) cSin.attach(self) cCos = QwtPlotCurve('y = cos(x)') cCos.setPen(QPen(Qt.blue)) cCos.attach(self) # make a Numeric array for the horizontal data x = np.arange(0.0, 10.0, 0.1) # initialize the data cSin.setData(x, np.sin(x)) cCos.setData(x, np.cos(x)) # insert a horizontal marker at y = 0 mY = QwtPlotMarker() mY.setLabel(QwtText('y = 0')) mY.setLabelAlignment(Qt.AlignRight | Qt.AlignTop) mY.setLineStyle(QwtPlotMarker.HLine) mY.setYValue(0.0) mY.attach(self) # insert a vertical marker at x = 2 pi mX = QwtPlotMarker() mX.setLabel(QwtText('x = 2 pi')) mX.setLabelAlignment(Qt.AlignRight | Qt.AlignTop) mX.setLineStyle(QwtPlotMarker.VLine) mX.setXValue(2 * np.pi) mX.attach(self) # replot self.replot()
def __init__(self, *args): QwtPlot.__init__(self, *args) global x, y, lineL, lineH, curveTemp HISTORY = 300 x = 0.1 * np.arange(0, -HISTORY, -1) y = np.zeros(HISTORY, np.float) self.setAxisScale(QwtPlot.yLeft, 0, 100) lineL = QwtPlotMarker() lineL.setLinePen(QtGui.QPen(QtCore.Qt.blue)) lineL.setLabelAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom) lineL.setLineStyle(QwtPlotMarker.HLine) lineL.setYValue(0) lineL.attach(self) lineH = QwtPlotMarker() lineH.setLinePen(QtGui.QPen(QtCore.Qt.red)) lineH.setLabelAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop) lineH.setLineStyle(QwtPlotMarker.HLine) lineH.setYValue(100) lineH.attach(self) curveTemp = QwtPlotCurve("实时温度") curveTemp.attach(self)
def main(args): app = QApplication(args) demo = QwtPlot() grid = QwtPlotGrid() grid.attach(demo) grid.setPen(QPen(Qt.black, 0, Qt.DotLine)) grid.enableX(True) grid.enableY(True) complex_divider = 50.0 myXScale = ComplexScaleDraw(start_value=0.0, end_value=complex_divider) #print('myXScale', myXScale) demo.setAxisScaleDraw(QwtPlot.xBottom, myXScale) m = QwtPlotMarker() m.attach(demo) m.setValue(complex_divider, 0.0) m.setLineStyle(QwtPlotMarker.VLine) m.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom) m.setLinePen(QPen(Qt.black, 2, Qt.SolidLine)) vector_array = numpy.zeros((100, ), numpy.float32) for i in range(100): vector_array[i] = i curve = QwtPlotCurve('example data') curve.attach(demo) x_array = numpy.zeros(100, numpy.float32) y_array = numpy.zeros(100, numpy.float32) for i in range(100): x_array[i] = 1.0 * i y_array[i] = 2.0 * i curve.setSamples(x_array, y_array) demo.resize(600, 400) demo.replot() demo.show() # app.setMainWidget(demo) app.exec_()
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, *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 __init__(self, *args): QwtPlot.__init__(self, *args) # set plot title self.setTitle('ImagePlot') # set plot layout self.plotLayout().setCanvasMargin(0) self.plotLayout().setAlignCanvasToScales(True) # set legend legend = QwtLegend() legend.setDefaultItemMode(QwtLegendData.Clickable) self.insertLegend(legend, QwtPlot.RightLegend) # set axis titles self.setAxisTitle(QwtPlot.xBottom, 'time (s)') self.setAxisTitle(QwtPlot.yLeft, 'frequency (Hz)') colorMap = QwtLinearColorMap(Qt.blue, Qt.red) interval = QwtInterval(-1, 1) self.enableAxis(QwtPlot.yRight) self.setAxisScale(QwtPlot.yRight, -1, 1) self.axisWidget(QwtPlot.yRight).setColorBarEnabled(True) self.axisWidget(QwtPlot.yRight).setColorMap(interval, colorMap) # calculate 3 NumPy arrays x = np.arange(-2 * np.pi, 2 * np.pi, 0.01) y = np.pi * np.sin(x) z = 4 * np.pi * np.cos(x) * np.cos(x) * np.sin(x) # attach a curve curve = QwtPlotCurve('y = pi*sin(x)') curve.attach(self) curve.setPen(QPen(Qt.green, 2)) curve.setData(x, y) # attach another curve curve = QwtPlotCurve('y = 4*pi*sin(x)*cos(x)**2') curve.attach(self) curve.setPen(QPen(Qt.black, 2)) curve.setData(x, z) # attach a grid grid = QwtPlotGrid() grid.attach(self) grid.setPen(QPen(Qt.black, 0, Qt.DotLine)) # attach a horizontal marker at y = 0 marker = QwtPlotMarker() marker.attach(self) marker.setValue(0.0, 0.0) marker.setLineStyle(QwtPlotMarker.HLine) marker.setLabelAlignment(Qt.AlignRight | Qt.AlignTop) marker.setLabel(QwtText('y = 0')) # attach a vertical marker at x = pi marker = QwtPlotMarker() marker.attach(self) marker.setValue(np.pi, 0.0) marker.setLineStyle(QwtPlotMarker.VLine) marker.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom) marker.setLabel(QwtText('x = pi')) # attach a plot image plotImage = PlotImage('Image') plotImage.attach(self) plotImage.setData(square(512, -2 * np.pi, 2 * np.pi), (-2 * np.pi, 2 * np.pi), (-2 * np.pi, 2 * np.pi)) legend.SIG_CLICKED.connect(self.toggleVisibility) # replot self.replot()
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 __init__(self, *args): QwtPlot.__init__(self, *args) # set plot title self.setTitle('ImagePlot') # set plot layout self.plotLayout().setCanvasMargin(0) self.plotLayout().setAlignCanvasToScales(True) # set legend legend = QwtLegend() legend.setDefaultItemMode(QwtLegendData.Clickable) self.insertLegend(legend, QwtPlot.RightLegend) # set axis titles self.setAxisTitle(QwtPlot.xBottom, 'time (s)') self.setAxisTitle(QwtPlot.yLeft, 'frequency (Hz)') colorMap = QwtLinearColorMap(Qt.blue, Qt.red) interval = QwtInterval(-1, 1) self.enableAxis(QwtPlot.yRight) self.setAxisScale(QwtPlot.yRight, -1, 1) self.axisWidget(QwtPlot.yRight).setColorBarEnabled(True) self.axisWidget(QwtPlot.yRight).setColorMap(interval, colorMap) # calculate 3 NumPy arrays x = np.arange(-2*np.pi, 2*np.pi, 0.01) y = np.pi*np.sin(x) z = 4*np.pi*np.cos(x)*np.cos(x)*np.sin(x) # attach a curve curve = QwtPlotCurve('y = pi*sin(x)') curve.attach(self) curve.setPen(QPen(Qt.green, 2)) curve.setData(x, y) # attach another curve curve = QwtPlotCurve('y = 4*pi*sin(x)*cos(x)**2') curve.attach(self) curve.setPen(QPen(Qt.black, 2)) curve.setData(x, z) # attach a grid grid = QwtPlotGrid() grid.attach(self) grid.setPen(QPen(Qt.black, 0, Qt.DotLine)) # attach a horizontal marker at y = 0 marker = QwtPlotMarker() marker.attach(self) marker.setValue(0.0, 0.0) marker.setLineStyle(QwtPlotMarker.HLine) marker.setLabelAlignment(Qt.AlignRight | Qt.AlignTop) marker.setLabel(QwtText('y = 0')) # attach a vertical marker at x = pi marker = QwtPlotMarker() marker.attach(self) marker.setValue(np.pi, 0.0) marker.setLineStyle(QwtPlotMarker.VLine) marker.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom) marker.setLabel(QwtText('x = pi')) # attach a plot image plotImage = PlotImage('Image') plotImage.attach(self) plotImage.setData(square(512, -2*np.pi, 2*np.pi), (-2*np.pi, 2*np.pi), (-2*np.pi, 2*np.pi)) legend.SIG_CLICKED.connect(self.toggleVisibility) # replot self.replot()