Ejemplo n.º 1
0
 def __init__(self):
     super(LogCurvePlot,
           self).__init__("LogCurveDemo.py (or how to handle -inf values)")
     self.enableAxis(QwtPlot.xBottom)
     self.setAxisScaleEngine(QwtPlot.yLeft, QwtLogScaleEngine())
     x = np.arange(0.0, 10.0, 0.1)
     y = 10 * np.cos(x)**2 - 0.1
     QwtPlotCurve.make(x,
                       y,
                       linecolor=Qt.magenta,
                       plot=self,
                       antialiased=True)
     self.replot()
Ejemplo n.º 2
0
 def __init__(self, *args):
     QwtPlot.__init__(self, *args)
     self.setTitle("Cartesian Coordinate System Demo")
     # create a plot with a white canvas
     self.setCanvasBackground(Qt.white)
     # set plot layout
     self.plotLayout().setCanvasMargin(0)
     self.plotLayout().setAlignCanvasToScales(True)
     # attach a grid
     QwtPlotGrid.make(self,
                      color=Qt.lightGray,
                      width=0,
                      style=Qt.DotLine,
                      z=-1)
     # attach a x-axis
     xaxis = CartesianAxis(QwtPlot.xBottom, QwtPlot.yLeft)
     xaxis.attach(self)
     self.enableAxis(QwtPlot.xBottom, False)
     # attach a y-axis
     yaxis = CartesianAxis(QwtPlot.yLeft, QwtPlot.xBottom)
     yaxis.attach(self)
     self.enableAxis(QwtPlot.yLeft, False)
     # calculate 3 NumPy arrays
     x = np.arange(-2 * np.pi, 2 * np.pi, 0.01)
     # attach a curve
     QwtPlotCurve.make(
         x,
         np.pi * np.sin(x),
         title="y = pi*sin(x)",
         linecolor=Qt.green,
         linewidth=2,
         plot=self,
         antialiased=True,
     )
     # attach another curve
     QwtPlotCurve.make(
         x,
         4 * np.pi * np.cos(x) * np.cos(x) * np.sin(x),
         title="y = 4*pi*sin(x)*cos(x)**2",
         linecolor=Qt.blue,
         linewidth=2,
         plot=self,
         antialiased=True,
     )
     self.replot()
Ejemplo n.º 3
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
        QwtPlotGrid.make(plot=self,
                         enableminor=(True, False),
                         color=Qt.darkGray)

        # 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.make(title="Amplitude",
                                        linecolor=Qt.yellow,
                                        plot=self,
                                        antialiased=True)
        self.curve2 = QwtPlotCurve.make(title="Phase",
                                        linecolor=Qt.cyan,
                                        plot=self,
                                        antialiased=True)
        self.dB3Marker = QwtPlotMarker.make(
            label=QwtText.make(color=Qt.white,
                               brush=Qt.red,
                               weight=QFont.Light),
            linestyle=QwtPlotMarker.VLine,
            align=Qt.AlignRight | Qt.AlignBottom,
            color=Qt.green,
            width=2,
            style=Qt.DashDotLine,
            plot=self,
        )
        self.peakMarker = QwtPlotMarker.make(
            label=QwtText.make(color=Qt.red,
                               brush=self.canvasBackground(),
                               weight=QFont.Bold),
            symbol=QwtSymbol.make(QwtSymbol.Diamond, Qt.yellow, Qt.green,
                                  (7, 7)),
            linestyle=QwtPlotMarker.HLine,
            align=Qt.AlignRight | Qt.AlignBottom,
            color=Qt.red,
            width=2,
            style=Qt.DashDotLine,
            plot=self,
        )
        QwtPlotMarker.make(
            xvalue=0.1,
            yvalue=-20.0,
            align=Qt.AlignRight | Qt.AlignBottom,
            label=QwtText.make(
                "[1-(\u03c9/\u03c9<sub>0</sub>)<sup>2</sup>+2j\u03c9/Q]"
                "<sup>-1</sup>",
                color=Qt.white,
                borderradius=2,
                borderpen=QPen(Qt.lightGray, 5),
                brush=Qt.lightGray,
                weight=QFont.Bold,
            ),
            plot=self,
        )

        self.setDamp(0.01)
Ejemplo n.º 4
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
        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()