Exemplo n.º 1
0
    def __init__(self, *args):
        super(GraphWidget, self).__init__(*args)
        self._legend = Qwt.QwtLegend()
        self.setCanvasBackground(Qt.white)
        self._legend.setItemMode(Qwt.QwtLegend.CheckableItem)
        self.insertLegend(self._legend, Qwt.QwtPlot.BottomLegend)

        self._curves = {}

        self._last_canvas_x = 0
        self._last_canvas_y = 0
        self._pressed_canvas_y = 0
        self._last_click_coordinates = None
        self._color_index = 0

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

        self.zoom_enabled = True

        # Initialize data
        self._newest_time = 0
        self._y_upper_limit = 0.01
        self._y_lower_limit = -0.01
        self._yaxis_updated = 0
        self._canvas_display_width = 10
        self.redraw()
        self.move_canvas(0, 0)
        self.canvas().setMouseTracking(True)
        self.canvas().installEventFilter(self)
Exemplo n.º 2
0
    def create_curves(self, labels, this_range, show_legend=True):

        # delete / detach all old curves
        for c in self.curves:
            c.detach()

        # create new curves
        self.curves = []
        for i, curve_label in enumerate(labels):

            # Create legend item and set font
            curve_label_t = Qwt.QwtText(str(curve_label))
            f = curve_label_t.font()
            f.setPointSize(8)
            curve_label_t.setFont(f)

            curve = Qwt.QwtPlotCurve(curve_label_t)
            curve.attach(self)
            curve.setPen(Qt.QPen(self.colors[i % len(self.colors)]))
            curve.setRenderHint(QwtPlotItem.RenderAntialiased,
                                USE_ANTIALIASING)
            self.curves.append(curve)

        if show_legend:
            legend = Qwt.QwtLegend()
            self.insertLegend(legend, Qwt.QwtPlot.BottomLegend)
            # self.insertLegend(legend, Qwt.QwtPlot.ExternalLegend);
        xaxis_title = Qwt.QwtText("Time (seconds)")
        yaxis_title = Qwt.QwtText("Intensity")
        self.setAxisTitle(Qwt.QwtPlot.xBottom, xaxis_title)
        self.setAxisTitle(Qwt.QwtPlot.yLeft, yaxis_title)
Exemplo n.º 3
0
    def __init__(self, y_axis, plot_list, *args):
        Qwt.QwtPlot.__init__(self, *args)

        self.setAxisTitle(Qwt.QwtPlot.xBottom, 'Time [s]')
        self.setAxisTitle(Qwt.QwtPlot.yLeft, y_axis)

        self.has_legend = plot_list[0][0] != ''

        if self.has_legend:
            legend = Qwt.QwtLegend()
            legend.setItemMode(Qwt.QwtLegend.CheckableItem)
            self.insertLegend(legend, Qwt.QwtPlot.RightLegend)

        self.setAutoReplot(True)

        self.curve = []

        self.data_x = []
        self.data_y = []

        for x in plot_list:
            c = Qwt.QwtPlotCurve(x[0])
            self.curve.append(c)
            self.data_x.append([])
            self.data_y.append([])

            c.attach(self)
            c.setPen(x[1])
            self.show_curve(c, True)

        if self.has_legend:
            self.legendChecked.connect(self.show_curve)
Exemplo n.º 4
0
def plot_production_by_state():
    """Show data in qwt plot"""

    plot = Qwt.QwtPlot()
    plot.setTitle("Oil Production by State")
    plot.setAxisTitle(Qwt.QwtPlot.xBottom, "Date")
    plot.setAxisTitle(Qwt.QwtPlot.yLeft, "Barrels (in thousands)")

    # Need custom scale to set labels to month/year
    plot.setAxisScaleDraw(Qwt.QwtPlot.xBottom, view.TimeScaleDraw())

    hdf5 = tables.openFile(model.HDF5_FILENAME)

    x_vals = hdf5.root.data.production_by_state_month.cols.date[:]
    la_vals = hdf5.root.data.production_by_state_month.cols.la_barrels[:]
    tx_vals = hdf5.root.data.production_by_state_month.cols.tx_barrels[:]
    ak_vals = hdf5.root.data.production_by_state_month.cols.ak_barrels[:]
    ca_vals = hdf5.root.data.production_by_state_month.cols.ca_barrels[:]

    curve = view.create_curve('La', x_vals, la_vals, QtCore.Qt.green)
    curve.attach(plot)

    curve = view.create_curve('Tx', x_vals, tx_vals, QtCore.Qt.blue)
    curve.attach(plot)

    curve = view.create_curve('Ak', x_vals, ak_vals, QtCore.Qt.red)
    curve.attach(plot)

    curve = view.create_curve('Ca', x_vals, ca_vals, QtCore.Qt.yellow)
    curve.attach(plot)

    plot.insertLegend(Qwt.QwtLegend())
    plot.replot()

    return plot
Exemplo n.º 5
0
    def __init__(self, comm, parent=None):
        """Connents newMessage handler to OvenComm instance and sets up common plot format."""
        super(OvenPlot, self).__init__(parent)

        self.comm = comm

        self.setCanvasBackground(QtCore.Qt.white)

        # plot grid
        grid = Qwt.QwtPlotGrid()
        pen = QtGui.QPen(QtCore.Qt.DotLine)
        pen.setColor(QtCore.Qt.black)
        pen.setWidth(0)
        grid.setPen(pen)
        grid.attach(self)

        # plot legend and x-axis (y-axis handled in derived classes)
        self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.BottomLegend)
        self.setAxisTitle(Qwt.QwtPlot.xBottom, "Time (seconds)")

        self.times = []
        self.time_offset = 0.0
        self.max_idle = (120 * 4)
        self.prevstate = 'idle'

        self.reset_plot()

        comm.newMessage.connect(self.newMessage_handler)
Exemplo n.º 6
0
    def __init__(self, nChip, myID, *args):
        Qwt.QwtPlot.__init__(self, *args)

        self.myID = myID
        self.cpuIdx = 0
        self.chipIdx = 0
        self.modeIdx = 0
        self.nChip = nChip
        if myID < 18:
            self.setCanvasBackground(Qt.Qt.white)
        else:
            self.setCanvasBackground(Qt.QColor(212, 212, 212))
            self.enableAxis(Qwt.QwtPlot.xBottom, False)
            self.enableAxis(Qwt.QwtPlot.yLeft, False)
            self.canvas().setFrameStyle(Qt.QFrame.NoFrame or Qt.QFrame.Plain)
            #qpl= Qt.QPalette()
            #qpl.setColor(Qt.QPalette.Active,Qt.QPalette.Window,Qt.QColor(212,212,212));
            #qpl.setColor(Qt.QPalette.Inactive,Qt.QPalette.Window,Qt.QColor(212,212,212));
            #qpl.setColor(Qt.QPalette.Disabled,Qt.QPalette.Window,Qt.QColor(212,212,212));
            #self.canvas().setPalette(qpl)

        self.alignScales()

        # Initialize data
        self.x = arange(0.0, 100.1, 0.5)

        # Initialize working parameters
        self.saveToFile = DEF_SAVE_TO_FILE
        # To avoid writing conflict, only core-0 is allowed to save to files
        if self.myID == 0:
            self.Ufiles = list()
            for i in range(nChip):
                self.Ufiles.append(None)

        self.u = list(
        )  # list of list, contains the utilization value for ALL chips
        #self.c = list()     # contains the curve value
        for i in range(nChip):
            y = zeros(len(self.x), float)
            self.u.append(y)
        #for i in range(18): # for all 18 cores in a chip
        if self.myID < 18:
            cname = "Core-%d" % (self.myID)
        else:
            cname = ""
        self.c = Qwt.QwtPlotCurve(cname)

        ## Color contants
        clr = [Qt.Qt.red, Qt.Qt.green, Qt.Qt.blue, Qt.Qt.cyan, Qt.Qt.magenta, Qt.Qt.yellow, Qt.Qt.black, Qt.Qt.gray, \
               Qt.Qt.darkRed, Qt.Qt.darkGreen, Qt.Qt.darkBlue, Qt.Qt.darkCyan, Qt.Qt.darkMagenta, Qt.Qt.darkYellow, \
               Qt.Qt.darkGray, Qt.Qt.lightGray, \
               Qt.QColor(Qt.qRgb(255,192,203)), Qt.QColor(Qt.qRgb(139,69,19)), Qt.QColor(Qt.qRgb(128, 0, 0)), Qt.Qt.white]
        #Pink: rgb(255,192,203), Brown: rgb(139,69,19), Maron: rgb(128,0,0)

        self.c.attach(self)
        if self.myID < 18:
            self.c.setPen(Qt.QPen(clr[self.myID], DEF.PEN_WIDTH))
            self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.BottomLegend)
        else:
            self.c.setPen(Qt.QPen(Qt.QColor(212, 212, 212), DEF.PEN_WIDTH))
Exemplo n.º 7
0
    def __init__(self, *args):
        Qwt.QwtPlot.__init__(self, *args)

        self.setCanvasBackground(Qt.Qt.white)
        self.alignScales()

        # Initialize data
        self.x = arange(0.0, 100.1, 0.5)
        self.y = zeros(len(self.x), Float)
        self.z = zeros(len(self.x), Float)

        self.setTitle("PyQwt Example")
        self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.BottomLegend)

        self.curveR = Qwt.QwtPlotCurve("Random Data")
        self.curveR.attach(self)

        self.curveR.setPen(Qt.QPen(Qt.Qt.red))

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

        self.setAxisTitle(Qwt.QwtPlot.xBottom, "Time (seconds)")
        self.setAxisTitle(Qwt.QwtPlot.yLeft, "Values")

        self.startTimer(1)
        self.phase = 0.0
        self.tstart = time.time()
        self.counter = 0
Exemplo n.º 8
0
    def __init__(self, states, parent=None):
        """init"""

        super(StateProductionDialog, self).__init__(parent)

        self._plot = Qwt.QwtPlot()

        self._plot.setCanvasBackground(QtCore.Qt.white)
        self._plot.setTitle("Oil Production by State")
        self._plot.setAxisTitle(Qwt.QwtPlot.xBottom, "Date")
        self._plot.setAxisTitle(Qwt.QwtPlot.yLeft, "Barrels (in thousands)")
        self._plot.insertLegend(Qwt.QwtLegend())

        # Need custom scale to set labels to month/year
        self._plot.setAxisScaleDraw(Qwt.QwtPlot.xBottom, TimeScaleDraw())

        self._curves = {}
        colors = [
            QtCore.Qt.green, QtCore.Qt.black, QtCore.Qt.blue, QtCore.Qt.red
        ]

        for color, st in izip_longest(colors, states, fillvalue=QtCore.Qt.red):
            self._curves[st] = create_curve(st, color)
            self._curves[st].attach(self._plot)

        vlayout = QtGui.QVBoxLayout()
        vlayout.setMargin(0)
        vlayout.addWidget(self._plot)

        self.setLayout(vlayout)
        self.setWindowTitle('Oil production by state')
Exemplo n.º 9
0
	def setdataTwoChannels(self, x, y, y2):
		if self.canvas_width <> self.cached_canvas.width():
			self.logger.push("timeplot : changed canvas width")
			self.canvas_width = self.cached_canvas.width()
			self.update_xscale()

		if not self.dual_channel:
			self.dual_channel = True
			self.curve2.attach(self)
  			# enable the legend
  			# (to discrimate between the two channels)
			self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.RightLegend)
		
		x_ms =  1e3*x
		needfullreplot = False
		if self.xmax <> x_ms[-1]:
			self.logger.push("timeplot : changing x scale")
			self.xmax = x_ms[-1]
			self.setAxisScale(Qwt.QwtPlot.xBottom, 0., self.xmax)
			self.update_xscale()
			needfullreplot = True

		y_interp = interp(self.xscaled, x_ms, y)
  		y_interp2 = interp(self.xscaled, x_ms, y2)
		ClassPlot.setdata(self, self.xscaled, y_interp)
		self.curve2.setData(self.xscaled, y_interp2)

		if needfullreplot:
			self.replot()
		else:
			# self.replot() would call updateAxes() which is dead slow (probably because it
			# computes label sizes); instead, let's just ask Qt to repaint the canvas next time
			# This works because we disable the cache
			self.cached_canvas.update()
Exemplo n.º 10
0
 def __init__(self, *args):
     Qwt.QwtPlot.__init__(self, *args)
     self.cpu_count=psutil.cpu_count()
     self.x = arange(-60,0, 1)
     self.cpu_percent=[]
     self.curve=[]
     legend = Qwt.QwtLegend()
     legend.setItemMode(Qwt.QwtLegend.CheckableItem)
     self.insertLegend(legend, Qwt.QwtPlot.RightLegend)
     for cpu_number in range(self.cpu_count):
         self.cpu_percent.append(0*self.x)
         self.curve.append(Qwt.QwtPlotCurve('CPU'+str(cpu_number)))
         self.curve[cpu_number].attach(self)
         self.curve[cpu_number].setData(self.x, self.cpu_percent[cpu_number])
         self.curve[cpu_number].setPen(QtGui.QPen(self.colors[cpu_number], 2))
         self.showCurve(self.curve[cpu_number], True)          
     
     #ustawienie osi
     self.setAxisScale(Qwt.QwtPlot.yLeft, 0, 100)
     self.setAxisTitle(Qwt.QwtPlot.yLeft, "Usage [%]")
             
     #Grid
     grid = Qwt.QwtPlotGrid()
     pen = QtGui.QPen(Qt.DotLine)
     pen.setColor(Qt.black)
     pen.setWidth(0)
     grid.setPen(pen)
     grid.attach(self)
     self.startTimer(1000)
     self.connect(self,QtCore.SIGNAL('legendChecked(QwtPlotItem*, bool)'),self.showCurve) #przepisac na nowy styl
     self.replot()
Exemplo n.º 11
0
    def __init__(self, *args):
        super(QwtChart, self).__init__(*args)
        # set title
        self.setTitle(u'<h4><font color=red>图表</font></h4>')
        # bgcolor
        self.setCanvasBackground(Qt.Qt.white)
        # legend
        self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.RightLegend)

        # a variation on the C++ example
        self.plotLayout().setAlignCanvasToScales(True)

        # grid
        grid = Qwt.QwtPlotGrid()
        grid.setPen(QtGui.QPen(Qt.Qt.gray, 0, Qt.Qt.DotLine))
        grid.attach(self)

        # set axis titles
        self.setAxisTitle(Qwt.QwtPlot.xBottom, u'X')
        self.setAxisTitle(Qwt.QwtPlot.yLeft, u'Amplitude')

        # set Scale Range
        self.setAxisScale(Qwt.QwtPlot.xBottom, 0.0, 1000.0)
        self.setAxisScale(Qwt.QwtPlot.yLeft, -10.0, 10.0)

        # picker
        self.picker = Qwt.QwtPlotPicker(
            Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft,
            Qwt.QwtPicker.PointSelection | Qwt.QwtPicker.DragSelection,
            Qwt.QwtPlotPicker.CrossRubberBand, Qwt.QwtPicker.AlwaysOn,
            self.canvas())
        self.picker.setRubberBandPen(QtGui.QPen(Qt.Qt.red))
        self.picker.setTrackerPen(QtGui.QPen(Qt.Qt.red))

        self.connect(self.picker, QtCore.SIGNAL('moved(const QPoint &)'),
                     self.moved)

        # insert a horizontal marker at y = 0
        mY = Qwt.QwtPlotMarker()
        mY.setLabel(Qwt.QwtText('y = 0'))
        mY.setLabelAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignTop)
        mY.setLineStyle(Qwt.QwtPlotMarker.HLine)
        mY.setLinePen(Qt.QPen(Qt.Qt.cyan, 1, Qt.Qt.DashDotLine))
        mY.setYValue(0.0)
        mY.attach(self)

        # insert a vertical marker at x = 500
        mX = Qwt.QwtPlotMarker()
        mX.setLabel(Qwt.QwtText('x = 500'))
        mX.setLabelAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignTop)
        mX.setLineStyle(Qwt.QwtPlotMarker.VLine)
        mX.setLinePen(QtGui.QPen(Qt.Qt.cyan, 1, Qt.Qt.DashDotLine))
        mX.setXValue(500)
        mX.attach(self)

        #Initialize data
        self.curves = []
        self.dataLength = 1000
        self.x = np.arange(0.0, 1001.0, 1.0)
Exemplo n.º 12
0
    def __init__(self, *args):
        super(Chart, self).__init__(*args)
        #set title
        self.setTitle(u'<h4><font color=red>图表</font></h4>')
        #背景色
        self.setCanvasBackground(Qt.Qt.white)
        #插入图例--曲线名
        self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.RightLegend)

        # a variation on the C++ example
        self.plotLayout().setAlignCanvasToScales(True)
        
        #创建网格
        grid = Qwt.QwtPlotGrid()
        grid.setPen(Qt.QPen(Qt.Qt.gray, 0, Qt.Qt.DotLine))
        grid.attach(self)
        
        # set axis titles
        self.setAxisTitle(Qwt.QwtPlot.xBottom, u'Time(s)')
        self.setAxisTitle(Qwt.QwtPlot.yLeft, u'Values')
        
        # set Scale Range
        self.setAxisScale(Qwt.QwtPlot.xBottom, 0.0, 10000.0)
        self.setAxisScale(Qwt.QwtPlot.yLeft, -10.0, 10.0)

        # insert a few curves
        self.curveA = Qwt.QwtPlotCurve(u'curveA')
        self.curveA.setPen(Qt.QPen(Qt.Qt.red))
        self.curveA.attach(self)

        self.curveB = Qwt.QwtPlotCurve(u'curveB')
        self.curveB.setPen(Qt.QPen(Qt.Qt.blue))
        self.curveB.attach(self)

        # insert a horizontal marker at y = xxx
        mY = Qwt.QwtPlotMarker()
        mY.setLabel(Qwt.QwtText('Maker:Y'))
        mY.setLabelAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignTop)
        mY.setLineStyle(Qwt.QwtPlotMarker.HLine)
        mY.setYValue(0.0)
        mY.setLinePen(Qt.QPen(Qt.Qt.green, 1, Qt.Qt.DashDotLine))
        mY.attach(self)

        # insert a vertical marker
        mX = Qwt.QwtPlotMarker()
        mX.setLabel(Qwt.QwtText('Maker:X'))
        mX.setLabelAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignTop)
        mX.setLineStyle(Qwt.QwtPlotMarker.VLine)
        mX.setXValue(5000)
        mX.setLinePen(Qt.QPen(Qt.Qt.green, 1, Qt.Qt.DashDotLine))
        mX.attach(self)


        #Initialize data
        self.x = np.arange(0.0, 10001.0, 1.0)
        self.curveAData = np.array([0], np.float)
        self.curveBData = np.array([0], np.float)
Exemplo n.º 13
0
    def __init__(self, *args):
        Qwt.QwtPlot.__init__(self, *args)

        self.curves = {}
        self.data = {}
        self.timeData = 1.0 * arange(HISTORY-1, -1, -1)
        self.memoryStat = MemoryStat()

        self.setAutoReplot(False)

        self.plotLayout().setAlignCanvasToScales(True)
        
        legend = Qwt.QwtLegend()
        legend.setItemMode(Qwt.QwtLegend.CheckableItem)
        self.insertLegend(legend, Qwt.QwtPlot.RightLegend)
        
        self.setAxisScaleDraw(
            Qwt.QwtPlot.xBottom, TimeScaleDraw(self.memoryStat.nowTime()))
        self.setAxisScale(Qwt.QwtPlot.xBottom, 0, HISTORY)
        self.setAxisLabelRotation(Qwt.QwtPlot.xBottom, -05.0)
        self.setAxisLabelAlignment(
            Qwt.QwtPlot.xBottom, Qt.Qt.AlignLeft | Qt.Qt.AlignBottom)

        self.yLeft = Qwt.QwtText(QtGui.QApplication.translate("MainWindow","Usage [%]", 
                            None, QtGui.QApplication.UnicodeUTF8))        
        self.setAxisTitle(Qwt.QwtPlot.yLeft, self.yLeft)
        self.setAxisScale(Qwt.QwtPlot.yLeft, 0, 100)
        self.setMinimumHeight(130)

        background = Background()
        background.attach(self)
     
     
        
        curve = MemoryCurve('Memory')
        curve.setColor(Qt.Qt.yellow)
        curve.attach(self)
        self.curves['Memory'] = curve
        self.data['Memory'] = zeros(HISTORY, Float)

        curve = MemoryCurve('Swap')
        curve.setColor(Qt.Qt.green)
        curve.setZ(curve.z() - 1.0)
        curve.attach(self)
        self.curves['Swap'] = curve
        self.data['Swap'] = zeros(HISTORY, Float)

        self.showCurve(self.curves['Memory'], True)
        self.showCurve(self.curves['Swap'], True)

        self.startTimer(1000)

        self.connect(self,
                     Qt.SIGNAL('legendChecked(QwtPlotItem*, bool)'),
                     self.showCurve)
        self.replot()
Exemplo n.º 14
0
    def __init__(self,
                 titlePlot="noTitleSet",
                 legendCurveOne="noLegendSet",
                 legendCurveTwo=None,
                 *args):  #, *args
        Qwt.QwtPlot.__init__(self, *args)  #, *args
        #print "TOTO:"+str(*args)
        self.setCanvasBackground(Qt.Qt.white)
        self.alignScales()

        # Initialize data
        #self.x = arange(0.0, 100.1, 0.5)
        self.x = arange(0.0, 500.1, 0.5)

        self.y = zeros(len(self.x), Float)
        self.z = zeros(len(self.x), Float)

        self.setTitle(titlePlot)
        self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.BottomLegend)

        self.curveOne = Qwt.QwtPlotCurve(legendCurveOne)
        self.curveOne.attach(self)

        self.setMarker(50, "Welcome\n")

        #self.startTimer(50)
        self.phase = 0.0
        self.isAnalysed = False

        self.legendCurveTwo = legendCurveTwo
        if not legendCurveTwo == None:  #and not self.isAnalysed:
            self.curveTwo = Qwt.QwtPlotCurve(legendCurveTwo)
            self.curveTwo.attach(self)

        #to add yellow circles
        #if not legendCurveTwo==None:
        #    self.curveTwo.setSymbol(Qwt.QwtSymbol(Qwt.QwtSymbol.Ellipse,
        #                                Qt.QBrush(),
        #                                Qt.QPen(Qt.Qt.yellow),
        #                                Qt.QSize(7, 7)))

        self.curveOne.setPen(Qt.QPen(Qt.Qt.red))
        if not legendCurveTwo == None:
            self.curveTwo.setPen(Qt.QPen(Qt.Qt.blue))

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

        self.setAxisTitle(Qwt.QwtPlot.xBottom, "Time (s)")
        self.setAxisTitle(Qwt.QwtPlot.yLeft, "Value [C]")
Exemplo n.º 15
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)
Exemplo n.º 16
0
    def on_show(self):
        self.plot.clear()
        self.plot.setAxisTitle(Qwt.QwtPlot.xBottom, 'x -->')
        self.plot.setAxisTitle(Qwt.QwtPlot.yLeft, 'y -->')

        grid = Qwt.QwtPlotGrid()
        pen = QPen(Qt.DotLine)
        pen.setColor(Qt.black)
        pen.setWidth(0)
        grid.setPen(pen)
        grid.attach(self.plot)

        has_series = False

        coloriter = iter(COLORS)

        for row in range(self.series_list_model.rowCount()):
            model_index = self.series_list_model.index(row, 0)
            checked = self.series_list_model.data(
                model_index, Qt.CheckStateRole) == QVariant(Qt.Checked)
            name = str(self.series_list_model.data(model_index).toString())

            if checked:
                has_series = True

                x_from = self.from_spin.value()
                x_to = self.to_spin.value()
                series = self.data.get_series_data(name)[x_from:x_to + 1]

                color = QColor(coloriter.next())

                curve = Qwt.QwtPlotCurve(name)
                pen = QPen(color)
                pen.setWidth(2)
                curve.setPen(pen)
                curve.setData(range(len(series)), series)

                curve.setSymbol(
                    Qwt.QwtSymbol(Qwt.QwtSymbol.Ellipse, QBrush(color),
                                  QPen(color), QSize(5, 5)))

                curve.attach(self.plot)

        if has_series and self.legend_cb.isChecked():
            self.plot.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.RightLegend)
        else:
            self.plot.insertLegend(None)

        self.plot.replot()
Exemplo n.º 17
0
 def _init_title_label_legend(self, right_plotlist, kwargs):
     """Init the title, axis labels and legends"""
     if kwargs.get('legend') is not None:
         legend_name = kwargs['legend'].title() + 'Legend'
         self.insertLegend(Qwt.QwtLegend(), getattr(Qwt.QwtPlot,
                                                    legend_name))
     if kwargs.get('title') is not None:
         self.setTitle(kwargs['title'])
     if kwargs.get('xaxis_label') is not None:
         self.setAxisTitle(Qwt.QwtPlot.xBottom, kwargs['xaxis_label'])
     if kwargs.get('yaxis_left_label') is not None:
         self.setAxisTitle(Qwt.QwtPlot.yLeft, kwargs['yaxis_left_label'])
     if kwargs.get('yaxis_right_label') is not None and \
             right_plotlist is not None:
         self.setAxisTitle(Qwt.QwtPlot.yRight, kwargs['yaxis_right_label'])
Exemplo n.º 18
0
    def __init__(self, *args):
        Qwt.QwtPlot.__init__(self, *args)

        # make a QwtPlot widget
        self.setTitle('SimpleDemo.py')
        self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.RightLegend)

        # a variation on the C++ example
        self.plotLayout().setAlignCanvasToScales(True)
        grid = Qwt.QwtPlotGrid()
        grid.attach(self)
        grid.setPen(Qt.QPen(Qt.Qt.black, 0, Qt.Qt.DotLine))

        # set axis titles
        self.setAxisTitle(Qwt.QwtPlot.xBottom, 'x -->')
        self.setAxisTitle(Qwt.QwtPlot.yLeft, 'y -->')

        # insert a few curves
        cSin = Qwt.QwtPlotCurve('y = sin(x)')
        cSin.setPen(Qt.QPen(Qt.Qt.red))
        cSin.attach(self)

        cCos = Qwt.QwtPlotCurve('y = cos(x)')
        cCos.setPen(Qt.QPen(Qt.Qt.blue))
        cCos.attach(self)

        # initialize the data
        cSin.setData(SimpleData(math.sin, 100))
        cCos.setData(SimpleData(math.cos, 100))

        # insert a horizontal marker at y = 0
        mY = Qwt.QwtPlotMarker()
        mY.setLabel(Qwt.QwtText('y = 0'))
        mY.setLabelAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignTop)
        mY.setLineStyle(Qwt.QwtPlotMarker.HLine)
        mY.setYValue(0.0)
        mY.attach(self)

        # insert a vertical marker at x = 2 pi
        mX = Qwt.QwtPlotMarker()
        mX.setLabel(Qwt.QwtText('x = 2 pi'))
        mX.setLabelAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignTop)
        mX.setLineStyle(Qwt.QwtPlotMarker.VLine)
        mX.setXValue(2 * math.pi)
        mX.attach(self)

        # replot
        self.replot()
    def __init__(self, grblock, *args):
        Qwt.QwtPlot.__init__(self, *args)

        self.setCanvasBackground(Qt.Qt.white)

        self.grblock = grblock

        # Initialize data
        self.t = np.arange(self.grblock.ntau)
        self.pdp = np.zeros(self.t.size)

        self.setTitle("Power Delay Profile")
        self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.BottomLegend)

        self.pdpcurve = Qwt.QwtPlotCurve("PDP")
        self.pdpcurve.attach(self)

        self.pdpcurve.setPen(Qt.QPen(Qt.Qt.red))

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

        self.setAxisTitle(Qwt.QwtPlot.xBottom, "Time (seconds)")
        scale = time_scale(self.grblock.t_symbol)
        self.setAxisScaleDraw(Qwt.QwtPlot.xBottom, scale)

        self.setAxisTitle(Qwt.QwtPlot.yLeft, "Power")
        self.setAxisScale(Qwt.QwtPlot.yLeft, -100, 0)
        # for linear scale
        #self.setAxisScale(Qwt.QwtPlot.yLeft, 0, 2)

        # zoomer
        self.zoomer = Qwt.QwtPlotZoomer(Qwt.QwtPlot.xBottom, Qwt.QwtPlot.yLeft,
                                        Qwt.QwtPicker.DragSelection,
                                        Qwt.QwtPicker.AlwaysOff, self.canvas())
        self.zoomer.setRubberBandPen(Qt.QPen(Qt.Qt.green))

        # picker showing the coordinates at the mouse pointer
        self.picker = QwtPlotPicker(self.grblock.t_symbol, Qwt.QwtPlot.xBottom,
                                    Qwt.QwtPlot.yLeft,
                                    Qwt.QwtPicker.PointSelection,
                                    Qwt.QwtPlotPicker.CrossRubberBand,
                                    Qwt.QwtPicker.AlwaysOn, self.canvas())
        self.picker.setTrackerPen(Qt.QPen(Qt.Qt.cyan))
Exemplo n.º 20
0
    def __init__(self, *args):
        Qwt.QwtPlot.__init__(self, *args)

        self.setCanvasBackground(Qt.Qt.white)
        self.alignScales()

        self.curves = []
        self.curve_names = dict()

        self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.RightLegend)

        self.setAxisScaleEngine(self.xBottom, MinXScaleEngine(20))

        self.xLabel("Time (seconds)")
        self.yLabel("Values")

        self.firstTime = None
Exemplo n.º 21
0
    def __init__(self, *args):
        Qwt.QwtPlot.__init__(self, *args)

        # make a QwtPlot widget
        self.setTitle('ReallySimpleDemo.py')
        self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.RightLegend)

        # set axis titles
        self.setAxisTitle(Qwt.QwtPlot.xBottom, 'x -->')
        self.setAxisTitle(Qwt.QwtPlot.yLeft, 'y -->')

        # insert a few curves
        cSin = Qwt.QwtPlotCurve('y = sin(x)')
        cSin.setPen(Qt.QPen(Qt.Qt.red))
        cSin.attach(self)

        cCos = Qwt.QwtPlotCurve('y = cos(x)')
        cCos.setPen(Qt.QPen(Qt.Qt.blue))
        cCos.attach(self)

        # make a Numeric array for the horizontal data
        x = arange(0.0, 10.0, 0.1)

        # initialize the data
        cSin.setData(x, sin(x))
        cCos.setData(x, cos(x))

        # insert a horizontal marker at y = 0
        mY = Qwt.QwtPlotMarker()
        mY.setLabel(Qwt.QwtText('y = 0'))
        mY.setLabelAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignTop)
        mY.setLineStyle(Qwt.QwtPlotMarker.HLine)
        mY.setYValue(0.0)
        mY.attach(self)

        # insert a vertical marker at x = 2 pi
        mX = Qwt.QwtPlotMarker()
        mX.setLabel(Qwt.QwtText('x = 2 pi'))
        mX.setLabelAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignTop)
        mX.setLineStyle(Qwt.QwtPlotMarker.VLine)
        mX.setXValue(2 * pi)
        mX.attach(self)

        # replot
        self.replot()
Exemplo n.º 22
0
    def __init__(self, *args):

        # initialize the parent class
        Qwt.QwtPlot.__init__(self, *args)

        # set of ScopeChannel objects, indexed by name
        self.channels = dict()

        # configure the parent QwtPlot widget for a reasonable display
        self.setCanvasBackground(Qt.Qt.white)
        self._alignScales()
        self.setTitle("ArduinoScope")
        self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.BottomLegend)

        self.setAxisTitle(Qwt.QwtPlot.xBottom, "Time (seconds)")
        self.setAxisTitle(Qwt.QwtPlot.yLeft, "Values")

        return
Exemplo n.º 23
0
    def init_window(self):
        self.setCanvasBackground(Qt.Qt.white)
        #self.alignScales()

        self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.BottomLegend)

        #
        # Insert a horizontal maker
        mY = Qwt.QwtPlotMarker()
        mY.setLabelAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignTop)
        mY.setLineStyle(Qwt.QwtPlotMarker.HLine)
        mY.setYValue(0.0)
        mY.attach(self)

        self.setAxisTitle(Qwt.QwtPlot.xBottom, "Time (seconds)")

        self.setAxisTitle(Qwt.QwtPlot.yLeft, "Values")
        self.setAxisScale(Qwt.QwtPlot.yLeft, -200, 200)
Exemplo n.º 24
0
    def __init__(self, *args):
        # call base class constructor
        Qwt.QwtPlot.__init__(self, *args)

        self.setCanvasBackground(Qt.Qt.white)

        # 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)

        # title
        self.setTitle("A Moving QwtPlot Demonstration")
        # legend
        self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.BottomLegend)

        # plot going right
        self.curveR = Qwt.QwtPlotCurve("Data Moving Right")
        self.curveR.attach(self)
        # plot going left
        self.curveL = Qwt.QwtPlotCurve("Data Moving Left")
        self.curveL.attach(self)

        # accent on each data point of plot going left
        self.curveL.setSymbol(
            Qwt.QwtSymbol(Qwt.QwtSymbol.Ellipse, Qt.QBrush(),
                          Qt.QPen(Qt.Qt.yellow), Qt.QSize(7, 7)))

        # line colors
        self.curveR.setPen(Qt.QPen(Qt.Qt.red))
        self.curveL.setPen(Qt.QPen(Qt.Qt.blue))

        # set a line marker at zero
        mY = Qwt.QwtPlotMarker()
        mY.setLabelAlignment(Qt.Qt.AlignRight | Qt.Qt.AlignTop)
        mY.setLineStyle(Qwt.QwtPlotMarker.HLine)
        mY.setYValue(0.0)
        mY.attach(self)

        # axis titles
        self.setAxisTitle(Qwt.QwtPlot.xBottom, "Time (seconds)")
        self.setAxisTitle(Qwt.QwtPlot.yLeft, "Values")

        self.phase = 0.0
Exemplo n.º 25
0
    def preparePlot(self):
        """Prepare the plotting window"""
        if self.figure:
            return
        self.figure = Qwt.QwtPlot()
        self.figure.setCanvasBackground(Qt.Qt.white)
        self.figure.canvas().setFrameStyle(Qt.QFrame.Box | Qt.QFrame.Plain)
        self.figure.canvas().setLineWidth(1)
        for i in range(Qwt.QwtPlot.axisCnt):
            scaleWidget = self.figure.axisWidget(i)
            if scaleWidget:
                scaleWidget.setMargin(0)
            scaleDraw = self.figure.axisScaleDraw(i)
            if scaleDraw:
                scaleDraw.enableComponent(Qwt.QwtAbstractScaleDraw.Backbone,
                                          False)
        self.figure.setTitle("Figure: %d - %s" % (self.figNr, self.title))
        self.figure.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.BottomLegend)

        self.figure.setAxisTitle(Qwt.QwtPlot.xBottom, "Time")
        self.figure.setAxisTitle(Qwt.QwtPlot.yLeft, self.ylabel)
        self.axis1 = Qwt.QwtPlot.yLeft
        if len(self.alternate) > 0:
            self.figure.enableAxis(Qwt.QwtPlot.yRight)
            self.figure.setAxisTitle(Qwt.QwtPlot.yRight, self.ylabel2)
            self.axis2 = Qwt.QwtPlot.yRight

        if self.spec.logscale:
            self.figure.setAxisScaleEngine(Qwt.QwtPlot.yLeft,
                                           Qwt.QwtLog10ScaleEngine())
            if len(self.alternate) > 0:
                self.figure.setAxisScaleEngine(Qwt.QwtPlot.yRight,
                                               Qwt.QwtLog10ScaleEngine())

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

        self.figure.resize(500, 300)
        self.figure.show()
Exemplo n.º 26
0
    def initialize(self):
        # attach a horizontal marker at y = 0
        self.clear()
        self.curves = {}
        # set Markers
        marker = Qwt.QwtPlotMarker()
        marker.attach(self)
        marker.setValue(0.0, 25.0)
        marker.setLineStyle(Qwt.QwtPlotMarker.HLine)
        marker.setLabelAlignment(Qt.Qt.AlignLeft | Qt.Qt.AlignTop)
        marker.setLabel(Qwt.QwtText('NDVI = 0'))
        #
        self.pointMarker = Qwt.QwtPlotMarker()
        self.pointMarker.attach(self)

        # set Legend
        legend = Qwt.QwtLegend()
        legend.setItemMode(Qwt.QwtLegend.CheckableItem)
        self.insertLegend(legend, Qwt.QwtPlot.RightLegend)
        self.connect(self, Qt.SIGNAL('legendChecked(QwtPlotItem*, bool)'),
                     self.showCurve)
Exemplo n.º 27
0
   def __init__(self, multimeter, *args):
       Qwt.QwtPlot.__init__(self, *args)

       self.multimeter = multimeter

       self.setCanvasBackground(Qt.Qt.white)
       self.alignScales()

       # Initialize data
       self.x = arange(0.0, 100.1, 0.5)
       self.y = zeros(len(self.x), Float)
       #self.z = zeros(len(self.x), Float)

       self.setTitle("A Moving QwtPlot Demonstration")
       self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.BottomLegend);

       #self.curveR = Qwt.QwtPlotCurve("Data Moving Right")
       #self.curveR.attach(self)
       self.curveL = Qwt.QwtPlotCurve("Data Moving Left")
       self.curveL.attach(self)

       self.curveL.setSymbol(Qwt.QwtSymbol(Qwt.QwtSymbol.Ellipse,
                                       Qt.QBrush(),
                                       Qt.QPen(Qt.Qt.yellow),
                                       Qt.QSize(7, 7)))

       #self.curveR.setPen(Qt.QPen(Qt.Qt.red))
       self.curveL.setPen(Qt.QPen(Qt.Qt.blue))

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

       self.setAxisTitle(Qwt.QwtPlot.xBottom, "Time (seconds)")
       self.setAxisTitle(Qwt.QwtPlot.yLeft, "Values")

       self.startTimer(50)
       self.phase = 0.0
    def __init__(self, y_axis, plot_list, *args):
        Qwt.QwtPlot.__init__(self, *args)

        self.setAxisTitle(Qwt.QwtPlot.xBottom, 'Time [s]')
        self.setAxisTitle(Qwt.QwtPlot.yLeft, y_axis)

        c = self.canvas()
        c.setPaintAttribute(Qwt.QwtPlotCanvas.PaintCached, False)
        c.setPaintAttribute(Qwt.QwtPlotCanvas.PaintPacked, True)

        self.has_legend = plot_list[0][0] != ''

        if self.has_legend:
            legend = Qwt.QwtLegend()
            legend.setItemMode(Qwt.QwtLegend.CheckableItem)
            self.insertLegend(legend, Qwt.QwtPlot.RightLegend)

        self.setAutoReplot(True)

        self.curve = []

        self.data_x = []
        self.data_y = []
        self.last_max_y = -1000000
        self.last_min_y = 1000000

        for x in plot_list:
            c = Qwt.QwtPlotCurve(x[0])
            c.setRenderHint(Qwt.QwtPlotItem.RenderAntialiased)
            self.curve.append(c)
            self.data_x.append([])
            self.data_y.append([])

            c.attach(self)
            c.setPen(x[1])
            self.show_curve(c, True)

        if self.has_legend:
            self.legendChecked.connect(self.show_curve)
Exemplo n.º 29
0
    def __init__(self, *args):
        Qwt.QwtPlot.__init__(self, *args)

        self.setCanvasBackground(QColor("LightGrey"))

        self.colors = itertools.cycle([
            Qt.red, Qt.green, Qt.blue, Qt.cyan, Qt.magenta, Qt.yellow,
            Qt.darkRed, Qt.darkGreen, Qt.darkBlue, Qt.darkCyan, Qt.darkMagenta,
            Qt.darkYellow
        ])

        # legend

        self.legend = Qwt.QwtLegend()
        self.legend.setItemMode(Qwt.QwtLegend.ClickableItem)
        self.legend.setFrameStyle(QFrame.Box | QFrame.Sunken)
        self.insertLegend(self.legend, Qwt.QwtPlot.RightLegend)

        self.connect(self, SIGNAL("legendClicked(QwtPlotItem *)"),
                     self.legendClicked)
        # Axes

        self.setAxisScaleEngine(Qwt.QwtPlot.yLeft, Qwt.QwtLog10ScaleEngine())
        self.setAxisScaleEngine(Qwt.QwtPlot.yRight, Qwt.QwtLinearScaleEngine())

        self.axisScaleEngine(Qwt.QwtPlot.yLeft).setAttribute(
            Qwt.QwtScaleEngine.Floating)

        self.setAxisTitle(Qwt.QwtPlot.xBottom, "Time [h:m:s]")

        sd = TimeScaleDraw()
        self.setAxisScaleDraw(Qwt.QwtPlot.xBottom, sd)

        self.enableAxis(Qwt.QwtPlot.yRight)

        # Setup list of plots to hold

        self.curve = {}
Exemplo n.º 30
0
 def __showPlot(self, plotName, _mutex=None):
     _plotName = str(plotName)
     if (not _plotName in self.plotData.keys()) or (
             not _plotName in self.plotDrawingObjects.keys()):
         return
     if not self.plotData[_plotName][self.dirtyFlagIndex]:
         return
     drawingObjects = self.plotDrawingObjects[_plotName]
     drawingObjects["curve"].attach(self.pW)
     drawingObjects["curve"].setPen(
         QPen(QColor(drawingObjects["LineColor"]),
              drawingObjects["LineWidth"]))
     drawingObjects["curve"].setData(self.plotData[_plotName][0],
                                     self.plotData[_plotName][1])
     self.plotData[_plotName][self.dirtyFlagIndex] = False
     if self.autoLegendFlag and not self.legendSetFlag:
         self.legend = Qwt.QwtLegend()
         self.legend.setFrameStyle(QFrame.Box | QFrame.Sunken)
         self.legend.setItemMode(Qwt.QwtLegend.ClickableItem)
         self.pW.insertLegend(self.legend, self.legendPosition)
         self.legendSetFlag = True
     self.pW.replot()
     self.plotWindowInterfaceMutex.unlock()