示例#1
0
    def initPlotwindow(self,y,samplingrate):
        self.samplingrate = samplingrate;

        # set axis titles
        self.setAxisTitle(Qwt.QwtPlot.xBottom, 't/sec -->')
        self.setAxisTitle(Qwt.QwtPlot.yLeft, 'U/Volt -->')

        # insert a few curves
        self.cData = Qwt.QwtPlotCurve('y = voltage')
        self.cData.setPen(Qt.QPen(Qt.Qt.red))
        self.cData.attach(self)

        # make a Numeric array for the horizontal data
        self.x = np.arange(0.0, 500, 1)
        self.x = self.x / samplingrate;
        # sneaky way of creating an array of just zeroes
        self.y = self.x * 0 + y

        # initialize the data
        self.cData.setData(self.x,self.y)

        # insert a horizontal marker at y = 0
        mY = Qwt.QwtPlotMarker()
        mY.setLineStyle(Qwt.QwtPlotMarker.HLine)
        mY.setYValue(0.0)
        mY.attach(self)

        # replot
        self.replot()
示例#2
0
        def __init__(self, *args):
            super(DataPlot, self).__init__(*args)
            self.setCanvasBackground(Qt.white)
            self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.BottomLegend)

            self.curves = {}
            self.pauseFlag = False
            self.dataOffsetX = 0
            self.canvasOffsetX = 0
            self.canvasOffsetY = 0
            self.lastCanvasX = 0
            self.lastCanvasY = 0
            self.pressedCanvasY = 0
            self.redrawOnEachUpdate = False
            self.redrawOnFullUpdate = True
            self.redrawTimerInterval = None
            self.redrawManually = False
            self.oscilloscopeNextDataPosition = 0
            self.oscilloscopeMode = False
            self.lastClickCoordinates = None

            markerAxisY = Qwt.QwtPlotMarker()
            markerAxisY.setLabelAlignment(Qt.AlignRight | Qt.AlignTop)
            markerAxisY.setLineStyle(Qwt.QwtPlotMarker.HLine)
            markerAxisY.setYValue(0.0)
            markerAxisY.attach(self)

            #self.setAxisTitle(Qwt.QwtPlot.xBottom, "Time")
            #self.setAxisTitle(Qwt.QwtPlot.yLeft, "Value")


            self.picker = Qwt.QwtPlotPicker(
                Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft, Qwt.QwtPicker.PolygonSelection,
                Qwt.QwtPlotPicker.PolygonRubberBand, Qwt.QwtPicker.AlwaysOn, self.canvas()
            )
            self.picker.setRubberBandPen(QPen(self.colors[-1]))
            self.picker.setTrackerPen(QPen(self.colors[-1]))

            # Initialize data
            self.timeAxis = arange(self.dataNumValuesPloted)
            self.canvasDisplayHeight = 1000
            self.canvasDisplayWidth = self.canvas().width()
            self.dataOffsetX = self.dataNumValuesSaved - len(self.timeAxis)
            self.redraw()
            self.moveCanvas(0, 0)
            self.canvas().setMouseTracking(True)
            self.canvas().installEventFilter(self)

            # init and start redraw timer
            self.timerRedraw = QTimer(self)
            self.timerRedraw.timeout.connect(self.redraw)
            if self.redrawTimerInterval:
                self.timerRedraw.start(self.redrawTimerInterval)
示例#3
0
文件: qplt.py 项目: CaptainAL/Spyder
def testIPlot():
    if 'np' not in dir():
        import PyQt4.Qwt5.anynumpy as np
    x = np.arange(-2*np.pi, 2*np.pi, 0.01)
    p = IPlot(Axis(Bottom, "linear x-axis"),
              Axis(Left, "linear y-axis"),
              Axis(Right, Log, "logarithmic y-axis"),             
              Curve(x, np.cos(x), Pen(Magenta, 2), "cos(x)"),
              Curve(x, np.exp(x), Pen(Red), "exp(x)", Right),
              "PyQwt using Qt-%s and Qwt-%s"% (QT_VERSION_STR, QWT_VERSION_STR),
              )
    x = x[0:-1:10]
    p.plot(
        Curve(x, np.cos(x-np.pi/4), Symbol(Circle, Yellow), "circle"),
        Curve(x, np.cos(x+np.pi/4), Pen(Blue), Symbol(Square, Cyan), "square"),
        )
    return p
示例#4
0
    def update_plot(self, new_t, new_vals):

        if self.first_update:            
            self.first_update = False
            self.n = 0            
            self.tmin = new_t
            self.tmax = self.tmin + self.window
            self.t = np.arange(self.tmin, self.tmax, 0.1)
            for var in self.data:
                self.data[var] = np.zeros(len(self.t))            
            self.widget.setAxisScale(Qwt.QwtPlot.xBottom, self.tmin, self.tmax)        

        self.t[self.n] = new_t

        for var, val in new_vals.iteritems():
            self.data[var][self.n] = val
            self.curves[var].setData(self.t[:self.n], self.data[var][:self.n])
            #self.curves[var].setData(self.t, self.data[var])

        if self.tmax - self.t[self.n] < self.jump_threshold:
            self.tmin += self.jump
            self.tmax += self.jump             
            self.widget.setAxisScale(Qwt.QwtPlot.xBottom, self.tmin, self.tmax)
            # drop old data the will not be displayed.
            # find the index of the largest value in self.t that is less than tmin.
            cut_index = len(np.nonzero(self.t[:self.n] < self.tmin)[0])
            debug("tmin=%f tmax=%f cut=%d n=%d -> %d array_lenth=%d" % (
                self.tmin, self.tmax, cut_index, self.n, self.n - cut_index, len(self.t)))

            self.t = self.t[cut_index:]
            for var in self.data:
                self.data[var] = self.data[var][cut_index:]
            self.n -= cut_index
            assert(self.t[self.n] == new_t)
        
        self.n += 1

        if self.n >= len(self.t):
            debug("Extending arrays by %d samples" % (self.extra_samples))
            self.t = np.concatenate((self.t, np.zeros(self.extra_samples)))
            for var in self.data:
                self.data[var] = np.concatenate((self.data[var], np.zeros(self.extra_samples)))

        #self.widget.setAxisScale(Qwt.QwtPlot.xBottom, t[-1]-10, t[-1])        
        self.widget.replot()
    def setDamp(self, d):
        self.damping = d
        # Numerical Python: f, g, a and p are NumPy arrays!
        f = np.exp(np.log(10.0) * np.arange(-2, 2.02, 0.04))
        g = 1.0 / (1.0 - f * f + 2j * self.damping * f)
        a = 20.0 * np.log10(abs(g))
        p = 180 * np.arctan2(g.imag, g.real) / np.pi
        # for show3dB
        i3 = np.argmax(np.where(np.less(a, -3.0), a, -100.0))
        f3 = f[i3] - (a[i3] + 3.0) * (f[i3] - f[i3 - 1]) / (a[i3] - a[i3 - 1])
        # for showPeak
        imax = np.argmax(a)

        self.showPeak(f[imax], a[imax])
        self.show3dB(f3)
        self.showData(f, a, p)

        self.replot()
    def setDamp(self, d):
        self.damping = d
        # Numerical Python: f, g, a and p are NumPy arrays!
        f = np.exp(np.log(10.0)*np.arange(-2, 2.02, 0.04))
        g = 1.0/(1.0-f*f+2j*self.damping*f)
        a = 20.0*np.log10(abs(g))
        p = 180*np.arctan2(g.imag, g.real)/np.pi
        # for show3dB
        i3 = np.argmax(np.where(np.less(a, -3.0), a, -100.0))
        f3 = f[i3] - (a[i3]+3.0)*(f[i3]-f[i3-1])/(a[i3]-a[i3-1])
        # for showPeak
        imax = np.argmax(a)

        self.showPeak(f[imax], a[imax])
        self.show3dB(f3)
        self.showData(f, a, p)

        self.replot()
示例#7
0
文件: qplt.py 项目: gyenney/Tools
def testIPlot():
    if 'np' not in dir():
        import PyQt4.Qwt5.anynumpy as np
    x = np.arange(-2 * np.pi, 2 * np.pi, 0.01)
    p = IPlot(
        Axis(Bottom, "linear x-axis"),
        Axis(Left, "linear y-axis"),
        Axis(Right, Log, "logarithmic y-axis"),
        Curve(x, np.cos(x), Pen(Magenta, 2), "cos(x)"),
        Curve(x, np.exp(x), Pen(Red), "exp(x)", Right),
        "PyQwt using Qt-%s and Qwt-%s" % (QT_VERSION_STR, QWT_VERSION_STR),
    )
    x = x[0:-1:10]
    p.plot(
        Curve(x, np.cos(x - np.pi / 4), Symbol(Circle, Yellow), "circle"),
        Curve(x, np.cos(x + np.pi / 4), Pen(Blue), Symbol(Square, Cyan),
              "square"),
    )
    return p
 def _createPlotFrame(self, parent, plotName, xLabel, yLabel, curveNameColorPairs):
     """
     This function creates a curve with curveName of colour "color", x axis
     with xLabel and yAxis with yLabel
     """
     if hasattr(self, plotName):
         return getattr(self, plotName)
     frame = QtGui.QFrame(parent)
     frame.setFrameStyle(QtGui.QFrame.Panel | QtGui.QFrame.Sunken)
     plot = Qwt.QwtPlot( frame)
     setattr(self, plotName, plot)
     plot.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.RightLegend)
     plot.setAxisTitle(Qwt.QwtPlot.xBottom, xLabel)
     plot.setAxisTitle(Qwt.QwtPlot.yLeft, yLabel)
     x = numpy.arange(0.0, 6.28, 0.1)
     y = [numpy.sin(x),numpy.cos(x)]
     plot.replot()
     layout = QtGui.QVBoxLayout(frame)
     layout.addWidget(plot)
     frame.setLayout(layout)
     return frame
示例#9
0
 def rescaleAxisX(self, deltaX):
     newLen = len(self.timeAxis) + deltaX
     newLen = max(10, min(newLen, self.dataNumValuesSaved))
     self.timeAxis = arange(newLen)
     self.dataOffsetX = max(0, min(self.dataOffsetX, self.dataNumValuesSaved - len(self.timeAxis)))
     self.rescale()