コード例 #1
0
    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()
コード例 #2
0
    def __init__(self, *args):
        QwtPlot.__init__(self, *args)

        self.curves = {}
        self.data = {}
        self.timeData = 1.0 * np.arange(HISTORY-1, -1, -1)
        self.cpuStat = CpuStat()

        self.setAutoReplot(False)

        self.plotLayout().setAlignCanvasToScales(True)
        
        legend = QwtLegend()
        legend.setDefaultItemMode(QwtLegendData.Checkable)
        self.insertLegend(legend, QwtPlot.RightLegend)
        
        self.setAxisTitle(QwtPlot.xBottom, "System Uptime [h:m:s]")
        self.setAxisScaleDraw(
            QwtPlot.xBottom, TimeScaleDraw(self.cpuStat.upTime()))
        self.setAxisScale(QwtPlot.xBottom, 0, HISTORY)
        self.setAxisLabelRotation(QwtPlot.xBottom, -50.0)
        self.setAxisLabelAlignment(
            QwtPlot.xBottom, Qt.AlignLeft | Qt.AlignBottom)

        self.setAxisTitle(QwtPlot.yLeft, "Cpu Usage [%]")
        self.setAxisScale(QwtPlot.yLeft, 0, 100)

        background = Background()
        background.attach(self)

        pie = CpuPieMarker()
        pie.attach(self)
        
        curve = CpuCurve('System')
        curve.setColor(Qt.red)
        curve.attach(self)
        self.curves['System'] = curve
        self.data['System'] = np.zeros(HISTORY, np.float)

        curve = CpuCurve('User')
        curve.setColor(Qt.blue)
        curve.setZ(curve.z() - 1.0)
        curve.attach(self)
        self.curves['User'] = curve
        self.data['User'] = np.zeros(HISTORY, np.float)

        curve = CpuCurve('Total')
        curve.setColor(Qt.black)
        curve.setZ(curve.z() - 2.0)
        curve.attach(self)
        self.curves['Total'] = curve
        self.data['Total'] = np.zeros(HISTORY, np.float)

        curve = CpuCurve('Idle')
        curve.setColor(Qt.darkCyan)
        curve.setZ(curve.z() - 3.0)
        curve.attach(self)
        self.curves['Idle'] = curve
        self.data['Idle'] = np.zeros(HISTORY, np.float)

        self.showCurve(self.curves['System'], True)
        self.showCurve(self.curves['User'], True)
        self.showCurve(self.curves['Total'], False)
        self.showCurve(self.curves['Idle'], False)

        self.startTimer(1000)

        legend.SIG_CHECKED.connect(self.showCurve)
        self.replot()
コード例 #3
0
    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()
コード例 #4
0
ファイル: image.py プロジェクト: 1PYTHON1/PythonQwt
    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
        QwtPlotCurve.make(x,
                          y,
                          title="y = pi*sin(x)",
                          linecolor=Qt.green,
                          linewidth=2,
                          plot=self)
        # attach another curve
        QwtPlotCurve.make(x,
                          z,
                          title="y = 4*pi*sin(x)*cos(x)**2",
                          linewidth=2,
                          plot=self)
        # attach a grid
        grid = QwtPlotGrid()
        grid.attach(self)
        grid.setPen(QPen(Qt.black, 0, Qt.DotLine))
        # attach a horizontal marker at y = 0
        QwtPlotMarker.make(
            label="y = 0",
            linestyle=QwtPlotMarker.HLine,
            align=Qt.AlignRight | Qt.AlignTop,
            plot=self,
        )
        # attach a vertical marker at x = pi
        QwtPlotMarker.make(
            np.pi,
            0.0,
            label="x = pi",
            linestyle=QwtPlotMarker.VLine,
            align=Qt.AlignRight | Qt.AlignBottom,
            plot=self,
        )
        # 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.clicked.connect(self.toggleVisibility)

        # replot
        self.replot()
コード例 #5
0
    def __init__(self, unattended=False):
        QwtPlot.__init__(self)

        self.curves = {}
        self.data = {}
        self.timeData = 1.0 * np.arange(self.HISTORY - 1, -1, -1)
        self.cpuStat = CpuStat()

        self.setAutoReplot(False)

        self.plotLayout().setAlignCanvasToScales(True)

        legend = QwtLegend()
        legend.setDefaultItemMode(QwtLegendData.Checkable)
        self.insertLegend(legend, QwtPlot.RightLegend)

        self.setAxisTitle(QwtPlot.xBottom, "System Uptime [h:m:s]")
        self.setAxisScaleDraw(QwtPlot.xBottom,
                              TimeScaleDraw(self.cpuStat.upTime()))
        self.setAxisScale(QwtPlot.xBottom, 0, self.HISTORY)
        self.setAxisLabelRotation(QwtPlot.xBottom, -50.0)
        self.setAxisLabelAlignment(QwtPlot.xBottom,
                                   Qt.AlignLeft | Qt.AlignBottom)

        self.setAxisTitle(QwtPlot.yLeft, "Cpu Usage [%]")
        self.setAxisScale(QwtPlot.yLeft, 0, 100)

        background = Background()
        background.attach(self)

        pie = CpuPieMarker()
        pie.attach(self)

        curve = CpuCurve("System")
        curve.setColor(Qt.red)
        curve.attach(self)
        self.curves["System"] = curve
        self.data["System"] = np.zeros(self.HISTORY, float)

        curve = CpuCurve("User")
        curve.setColor(Qt.blue)
        curve.setZ(curve.z() - 1.0)
        curve.attach(self)
        self.curves["User"] = curve
        self.data["User"] = np.zeros(self.HISTORY, float)

        curve = CpuCurve("Total")
        curve.setColor(Qt.black)
        curve.setZ(curve.z() - 2.0)
        curve.attach(self)
        self.curves["Total"] = curve
        self.data["Total"] = np.zeros(self.HISTORY, float)

        curve = CpuCurve("Idle")
        curve.setColor(Qt.darkCyan)
        curve.setZ(curve.z() - 3.0)
        curve.attach(self)
        self.curves["Idle"] = curve
        self.data["Idle"] = np.zeros(self.HISTORY, float)

        self.showCurve(self.curves["System"], True)
        self.showCurve(self.curves["User"], True)
        self.showCurve(self.curves["Total"], False or unattended)
        self.showCurve(self.curves["Idle"], False or unattended)

        self.startTimer(20 if unattended else 1000)

        legend.checked.connect(self.showCurve)
        self.replot()