class MyWindow(QtGui.QMainWindow): """ This class implements a derivative of PyQt4.QtGui.QMainWindow, a complete application window, which can feature menus, submenus, status bar, etc. In this example, it uses few of those features. """ def __init__(self, parent=None): """ Constructor: creates an instance of MyWindow """ ######################################### # Necessary actions, which must be done # # for any project # ######################################### # first, calling the ancestor's creator QtGui.QMainWindow.__init__(self, parent) # get the User Interface from the module UI_p1 self.ui=Ui_MainWindow() # initialize the user interface self.ui.setupUi(self) ######################################### # Custom actions, which can be written # # in other ways for other projects. # ######################################### # aliases for some parts of the user interface self.plotWidget = self.ui.qwtPlot self.measureButton = self.ui.measureButton self.closeButton = self.ui.closeButton # connect methods to buttons' click signals self.measureButton.clicked.connect(self.measure) self.closeButton.clicked.connect(self.close) # initialize an empty curve for the plot widget self.curve = QwtPlotCurve() self.curve.attach(self.plotWidget) return def measure(self): """ This is a custom method to connect to the button for measurements. There is no need for another custom method, since the method "close" is already inherited from the ancestor class. """ # create data for a curve with some fixed # and some random features import random x=np.arange(0,8,1e-2) # abscissa: [0, 0.01, 0.02, ... 7.99] r=random.random() y=np.sin(x)+r*np.sin(3*x) # calculated ordinate # feed new data into the curve self.curve.setData(x,y,len(x)) # change the title of the plot on the fly self.plotWidget.setTitle("sin(x) + {} sin(3x)".format(r)) # display the result self.plotWidget.replot() return
def initQwtCurves(self): #BVP# self.BVP_plot.enableAxis(2, 0) self.BVP_plot.curve = QwtPlotCurve() self.BVP_plot.curve.setPen(QPen(Qt.darkBlue)) self.BVP_plot.curve.setStyle(QwtPlotCurve.Lines) self.BVP_plot.curve.setRenderHint(QwtPlotItem.RenderAntialiased) self.BVP_plot.curve.setPen(QPen(Qt.green)) self.BVP_plot.curve.attach(self.BVP_plot) self.BVP_plot.setAutoReplot(False) #GSR# self.GSR_plot.enableAxis(2, 0) self.GSR_plot.curve = QwtPlotCurve() self.GSR_plot.curve.setPen(QPen(Qt.darkBlue)) self.GSR_plot.curve.setStyle(QwtPlotCurve.Lines) self.GSR_plot.curve.setRenderHint(QwtPlotItem.RenderAntialiased) self.GSR_plot.curve.setPen(QPen(Qt.green)) self.GSR_plot.curve.attach(self.GSR_plot) self.GSR_plot.setAutoReplot(False) #TMP# self.TMP_plot.enableAxis(2, 0) self.TMP_plot.curve = QwtPlotCurve() self.TMP_plot.curve.setPen(QPen(Qt.darkBlue)) self.TMP_plot.curve.setStyle(QwtPlotCurve.Lines) self.TMP_plot.curve.setRenderHint(QwtPlotItem.RenderAntialiased) self.TMP_plot.curve.setPen(QPen(Qt.green)) self.TMP_plot.curve.attach(self.TMP_plot) self.TMP_plot.setAutoReplot(False)
class Example(QtGui.QWidget): def __init__(self): super(Example, self).__init__() self.initUI() self.current_y = 0 self.timer = QtCore.QTimer() self.timer.timeout.connect(self.update_plot) self.timer.setInterval(1000 / FREQ) self.timer.start() def initUI(self): self.setGeometry(300, 300, 1000, 1000) self.setWindowTitle('Icon') self.setWindowIcon(QtGui.QIcon('web.png')) self.plot = QwtPlot("Test", self) self.plot.resize(900, 900) self.curve = QwtPlotCurve("Curve 1") self.curve.attach(self.plot) self.show() def update_plot(self): self.curve.setData(x, ys[self.current_y]) self.current_y = (self.current_y + 1) % YS
def __init__(self, *args): QwtPlot.__init__(self, *args) self.setCanvasBackground(Qt.white) curva = QwtPlotCurve('Altitud') self.phase=0 ################################################## # Initialize data self.x = [0] self.y = [0] # Title of the graph self.g1title = "Altitude= " + str(self.x[0]) self.insertLegend(QwtLegend(), QwtPlot.BottomLegend); self.curveR = QwtPlotCurve("Altitude") self.curveR.attach(self) self.curveR.setPen(QPen(Qt.blue)) self.setAxisTitle(QwtPlot.xBottom, "Time (seconds)") self.setAxisTitle(QwtPlot.yLeft, "Altitude(m)") self.setAxisScale(QwtPlot.xBottom, 0.0, 20) self.setAxisScale(QwtPlot.yLeft, 0.0, 20) self.pal = QPalette() #####palette for background self.pal.setColor(QPalette.Text, Qt.white) self.pal.setColor(QPalette.Foreground, Qt.white) self.setPalette(self.pal) self.counter=0 ###counter for actualize data, is the same for all of the graphs/data grid = QwtPlotGrid() grid.attach(self) grid.setPen(QPen(Qt.black, 0, Qt.DotLine))
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
class Example(QtGui.QWidget): def __init__(self): super(Example, self).__init__() self.initUI() self.current_y = 0 self.timer = QtCore.QTimer() self.timer.timeout.connect(self.update_plot) self.timer.setInterval(1000/FREQ) self.timer.start() def initUI(self): self.setGeometry(300, 300, 1000, 1000) self.setWindowTitle('Icon') self.setWindowIcon(QtGui.QIcon('web.png')) self.plot = QwtPlot("Test", self) self.plot.resize(900, 900) self.curve = QwtPlotCurve("Curve 1") self.curve.attach(self.plot) self.show() def update_plot(self): self.curve.setData(x, ys[self.current_y]) self.current_y = (self.current_y + 1) % YS
def __init__(self, *args): QMainWindow.__init__(self, *args) self.plot = QwtPlot(self) self.plot.setTitle("A Simple Map Demonstration") self.plot.setCanvasBackground(Qt.white) self.plot.setAxisTitle(QwtPlot.xBottom, "x") self.plot.setAxisTitle(QwtPlot.yLeft, "y") self.plot.setAxisScale(QwtPlot.xBottom, 0.0, 1.0) self.plot.setAxisScale(QwtPlot.yLeft, 0.0, 1.0) self.setCentralWidget(self.plot) # Initialize map data self.count = self.i = 1000 self.xs = np.zeros(self.count, np.float) self.ys = np.zeros(self.count, np.float) self.kappa = 0.2 self.curve = QwtPlotCurve("Map") self.curve.attach(self.plot) self.curve.setSymbol( QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.red), QPen(Qt.blue), QSize(5, 5))) self.curve.setPen(QPen(Qt.cyan)) toolBar = QToolBar(self) self.addToolBar(toolBar) # 1 tick = 1 ms, 10 ticks = 10 ms (Linux clock is 100 Hz) self.ticks = 10 self.tid = self.startTimer(self.ticks) self.timer_tic = None self.user_tic = None self.system_tic = None self.plot.replot()
def __init__(self, x=[], y=[], symbolSizes=None): QwtPlotCurve.__init__(self) self.symbolSizes = symbolSizes self.symbolList = None self.setData(x, y, symbolSizes)
def MouseMoveEvent(self, e): """ callback to handle mouse moved event """ # print('in mouse move event') position = e.pos() xPos = position.x() yPos = position.y() self.xpos = self.invTransform(QwtPlot.xBottom, xPos) self.ypos = self.invTransform(QwtPlot.yLeft, yPos) if not self.xzoom_loc is None: self.xzoom_loc = [ self.press_xpos, self.press_xpos, self.xpos, self.xpos, self.press_xpos ] self.yzoom_loc = [ self.press_ypos, self.ypos, self.ypos, self.press_ypos, self.press_ypos ] if self.zoom_outline is None: self.zoom_outline = QwtPlotCurve() self.zoom_outline.setSamples(self.xzoom_loc, self.yzoom_loc) self.replot() # Test if mouse has moved outside the plot. If yes, we're # starting a drag. if xPos < self.xlb - 10 or xPos > self.xhb + 10 or yPos > self.ylb + 10 or yPos < self.yhb - 10: if not self.xzoom_loc is None: self.zoom_outline.detach() self.xzoom_loc = None self.yzoom_loc = None self.replot() self.startDrag(e)
def __init__( self, x=[], y=[], dx=None, dy=None, curvePen=None, curveStyle=None, curveSymbol=None, errorPen=None, errorCap=0, errorOnTop=False, ): """A curve of x versus y data with error bars in dx and dy. Horizontal error bars are plotted if dx is not None. Vertical error bars are plotted if dy is not None. x and y must be sequences with a shape (N,) and dx and dy must be sequences (if not None) with a shape (), (N,), or (2, N): - if dx or dy has a shape () or (N,), the error bars are given by (x-dx, x+dx) or (y-dy, y+dy), - if dx or dy has a shape (2, N), the error bars are given by (x-dx[0], x+dx[1]) or (y-dy[0], y+dy[1]). curvePen is the pen used to plot the curve curveStyle is the style used to plot the curve curveSymbol is the symbol used to plot the symbols errorPen is the pen used to plot the error bars errorCap is the size of the error bar caps errorOnTop is a boolean: - if True, plot the error bars on top of the curve, - if False, plot the curve on top of the error bars. """ QwtPlotCurve.__init__(self) if curvePen is None: curvePen = QPen(Qt.NoPen) if curveStyle is None: curveStyle = QwtPlotCurve.Lines if curveSymbol is None: curveSymbol = QwtSymbol() if errorPen is None: errorPen = QPen(Qt.NoPen) self.setData(x, y, dx, dy) self.setPen(curvePen) self.setStyle(curveStyle) self.setSymbol(curveSymbol) self.errorPen = errorPen self.errorCap = errorCap self.errorOnTop = errorOnTop
def initUI(self): self.setGeometry(300, 300, 1000, 1000) self.setWindowTitle('Icon') self.setWindowIcon(QtGui.QIcon('web.png')) self.plot = QwtPlot("Test", self) self.plot.resize(900, 900) self.curve = QwtPlotCurve("Curve 1") self.curve.attach(self.plot) self.show()
def do_compare_max(self, x_values): ### instantiate the envelop that will show min/max deviations self._max_envelop = self._y_values self._min_envelop = self._y_values self._max_crv = QwtPlotCurve('Zoomed max curve') self._max_crv.attach(self._plotter) self._min_crv = QwtPlotCurve('Zoomed min curve') self._min_crv.attach(self._plotter) self._max_crv.setData(x_values, self._max_envelop) self._min_crv.setData(x_values, self._min_envelop) self._compare_max = True
class MyWindow(QtGui.QMainWindow): """ This class implements a derivative of PyQt4.QtGui.QMainWindow, a complete application window, which can feature menus, submenus, status bar, etc. In this example, it uses few of those features. """ def __init__(self, parent=None): """ Constructor: creates an instance of MyWindow """ ######################################### # Necessary actions, which must be done # # for any project # ######################################### # first, calling the ancestor's creator QtGui.QMainWindow.__init__(self, parent) # get the User Interface from the module UI_p1 self.ui=Ui_MainWindow() # initialize the user interface self.ui.setupUi(self) ######################################### # Custom actions, which can be written # # in other ways for other projects. # ######################################### # aliases for some parts of the user interface self.plotWidget = self.ui.qwtPlot self.measureButton = self.ui.measureButton self.closeButton = self.ui.closeButton # connect methods to buttons' click signals self.measureButton.clicked.connect(self.measure) self.closeButton.clicked.connect(self.close) # initialize an empty curve for the plot widget self.curve = QwtPlotCurve() self.curve.attach(self.plotWidget) # initialize the driver for expEYES Junior self.p = ej.open() return def measure(self): """ This is a custom method to connect to the button for measurements. There is no need for another custom method, since the method "close" is already inherited from the ancestor class. """ t,v = self.p.capture(1,1000,200) self.curve.setData(t,v,len(t)) # display the result self.plotWidget.replot() return
def __init__(self, parent=None): QtGui.QMainWindow.__init__(self, parent) self.ui=Ui_MainWindow() self.ui.setupUi(self) # connect methods to buttons' click signals self.ui.wakeUpButton.clicked.connect(self.wakeUp) self.ui.stopButton.clicked.connect(self.stop) self.ui.closeButton.clicked.connect(self.close) self.ui.saveButton.clicked.connect(self.save) self.ui.immediateButton.clicked.connect(self.immediate) self.ui.finalButton.clicked.connect(self.final) self.ui.fitButton.clicked.connect(self.fit) self.ui.action_Save_Ctrl_S.triggered.connect(self.save) self.ui.action_Quit_Ctrl_Q.triggered.connect(self.close) self.ui.actionManual.triggered.connect(self.manual) self.ui.actionAbout.triggered.connect(self.about) self.ui.durationEdit.textChanged.connect(self.durationChanged) # create a timer self.stopTime=time.time() self.timer=QtCore.QTimer() # connect the timer to the "tick" callback method self.timer.timeout.connect(self.tick) # 20 times per second self.timer.start(50) # initialize an empty curve for the plot widget self.curve = QwtPlotCurve() self.curve0 = QwtPlotCurve() self.fitCurve1 = QwtPlotCurve() self.fitCurve2 = QwtPlotCurve() self.fitCurve3 = QwtPlotCurve() self.curve.attach(self.ui.qwtPlot) self.curve0.attach(self.ui.qwtPlot) self.fitCurve1.attach(self.ui.qwtPlot) self.fitCurve2.attach(self.ui.qwtPlot) self.fitCurve3.attach(self.ui.qwtPlot) # adjust the axis scales based on duration = 15 s self.durationChanged(15, ampl=5) # set the maxvalue for the threshold rate (in V/s) self.maxthreshold=150/15 # = 150/duration # expEYESdetection and initialization try: self.p = ej.open() assert(self.p.fd) self.setWindowTitle("expEYES Junior found on port {}".format( self.p.fd.port )) except: self.setWindowTitle("ERROR: expEYES Junior NOT FOUND!") self.ui.wakeUpButton.setEnabled(False) # custom properties self.isImmediate=True return
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()
def __init__(self, *args): QwtPlot.__init__(self, *args) # Initialize Decice address, #self.uut_dev = GPIBdevice.GPIBdevice(args[0]) self.rm = visa.ResourceManager() print(self.rm.list_resources()) self.uut_dev = self.rm.open_resource(args[0]) print('open pass') # Initialize 坐标轴 self.setCanvasBackground(Qt.white) self.alignScales() grid = QwtPlotGrid() grid.attach(self) grid.setMajorPen(QPen(Qt.black, 0, Qt.DotLine)) self.setAxisScale(QwtPlot.xBottom, 0.0, 300.1, 10.0) self.setAxisAutoScale(QwtPlot.yLeft, True) #self.setAxisScale(QwtPlot.yLeft,4.0,20.0,2.0) self.x = np.arange( 0.0, 300.1, 0.5 ) #0.25 for ONE POINT, THIS SHOULD BE Align to the reading rate:250ms self.z = np.zeros(len(self.x), np.float) self.setTitle("UUT Reading Monitor") self.insertLegend(QwtLegend(), QwtPlot.RightLegend) self.curveL = QwtPlotCurve("UUT Reading") self.curveL.attach(self) self.curveL.setPen(QPen(Qt.red)) self.setAxisTitle(QwtPlot.xBottom, "Time (seconds)") self.setAxisTitle(QwtPlot.yLeft, "UUT - Reading") self.replot() self.startTimer(500) #ms# FOR GET READING self.starttime = time.clock() #unit: s self.idx = 0 self.readfmt = "%.8f" self.Saveinfo("Starting...") IDN = self.uut_get_val(self.uut_dev, "*IDN?\r") print IDN print "Starting..."
def __init__(self, parent=None): """ Constructor: creates an instance of MyWindow """ ######################################### # Necessary actions, which must be done # # for any project # ######################################### # first, calling the ancestor's creator QtGui.QMainWindow.__init__(self, parent) # get the User Interface from the module UI_p1 self.ui=Ui_MainWindow() # initialize the user interface self.ui.setupUi(self) ######################################### # Custom actions, which can be written # # in other ways for other projects. # ######################################### # aliases for some parts of the user interface self.plotWidget = self.ui.qwtPlot self.measureButton = self.ui.measureButton self.closeButton = self.ui.closeButton # connect methods to buttons' click signals self.measureButton.clicked.connect(self.measure) self.closeButton.clicked.connect(self.close) # initialize 4 empty curves for the plot widget self.curves=[] colors=[ QtGui.QColor("#000000"), #black QtGui.QColor("#ff0000"), #red QtGui.QColor("#0000ff"), #blue QtGui.QColor("#00cc00"), #dark green ] for i in range(4): c=QwtPlotCurve() c.setPen(colors[i]) self.curves.append(c) c.attach(self.plotWidget) # initialize the driver for expEYES Junior # prevent an error if the box is not detected try: self.p = ej.open() assert(self.p.fd) self.setWindowTitle("expEYES Junior found on port {}".format( self.p.fd.port )) except: self.setWindowTitle("ERROR: expEYES Junior NOT FOUND!") self.measureButton.setEnabled(False) return
def setData(self, *args): """Set x versus y data with error bars in dx and dy. Horizontal error bars are plotted if dx is not None. Vertical error bars are plotted if dy is not None. x and y must be sequences with a shape (N,) and dx and dy must be sequences (if not None) with a shape (), (N,), or (2, N): - if dx or dy has a shape () or (N,), the error bars are given by (x-dx, x+dx) or (y-dy, y+dy), - if dx or dy has a shape (2, N), the error bars are given by (x-dx[0], x+dx[1]) or (y-dy[0], y+dy[1]). """ if len(args) == 1: QwtPlotCurve.setData(self, *args) return dx = None dy = None x, y = args[:2] if len(args) > 2: dx = args[2] if len(args) > 3: dy = args[3] self.__x = np.asarray(x, np.float) if len(self.__x.shape) != 1: raise RuntimeError('len(asarray(x).shape) != 1') self.__y = np.asarray(y, np.float) if len(self.__y.shape) != 1: raise RuntimeError('len(asarray(y).shape) != 1') if len(self.__x) != len(self.__y): raise RuntimeError('len(asarray(x)) != len(asarray(y))') if dx is None: self.__dx = None else: self.__dx = np.asarray(dx, np.float) if len(self.__dx.shape) not in [0, 1, 2]: raise RuntimeError('len(asarray(dx).shape) not in [0, 1, 2]') if dy is None: self.__dy = dy else: self.__dy = np.asarray(dy, np.float) if len(self.__dy.shape) not in [0, 1, 2]: raise RuntimeError('len(asarray(dy).shape) not in [0, 1, 2]') QwtPlotCurve.setData(self, self.__x, self.__y)
def __init__(self, *args): QwtPlot.__init__(self, *args) self.insertLegend(QwtLegend(), QwtPlot.RightLegend) self.enableAxis(self.xBottom) # insert a few curves self.Reward = QwtPlotCurve('Reward') self.Reward.setPen(QPen(Qt.darkGreen)) self.Reward.attach(self) # initialize the data self.Reward.setData([0], [0]) # replot self.replot()
def __init__(self, parent=None): """ Constructor: creates an instance of MyWindow """ ######################################### # Necessary actions, which must be done # # for any project # ######################################### # first, calling the ancestor's creator QtGui.QMainWindow.__init__(self, parent) # get the User Interface from the module UI_p1 self.ui=Ui_MainWindow() # initialize the user interface self.ui.setupUi(self) ######################################### # Custom actions, which can be written # # in other ways for other projects. # ######################################### # aliases for some parts of the user interface self.measureButton = self.ui.measureButton self.closeButton = self.ui.closeButton # connect methods to buttons' click signals self.measureButton.clicked.connect(self.measure) self.closeButton.clicked.connect(self.close) # initialize an empty curve for the signal plot widget self.signal = QwtPlotCurve() self.signal.attach(self.ui.signalPlot) self.ui.signalPlot.setAxisTitle(QwtPlot.xBottom, "t (ms)") self.ui.signalPlot.setAxisTitle(QwtPlot.yLeft, "voltage (V)") self.ui.signalPlot.setTitle("Signal") # and another for the fft plotwidget self.fft = QwtPlotCurve() self.fft.attach(self.ui.fftPlot) self.ui.fftPlot.setAxisTitle(QwtPlot.xBottom, "f (Hz)") self.ui.fftPlot.setAxisTitle(QwtPlot.yLeft, "amplitude") self.ui.fftPlot.setTitle("Fourier Transform") # initialize the driver for expEYES Junior # prevent an error if the box is not detected try: self.p = ej.open() assert(self.p.fd) self.setWindowTitle("expEYES Junior found on port {}".format( self.p.fd.port )) except: self.setWindowTitle("ERROR: expEYES Junior NOT FOUND!") self.measureButton.setEnabled(False) return
def __init__(self, x=[], y=[], dx=None, dy=None, curvePen=None, curveStyle=None, curveSymbol=None, errorPen=None, errorCap=0, errorOnTop=False): """A curve of x versus y data with error bars in dx and dy. Horizontal error bars are plotted if dx is not None. Vertical error bars are plotted if dy is not None. x and y must be sequences with a shape (N,) and dx and dy must be sequences (if not None) with a shape (), (N,), or (2, N): - if dx or dy has a shape () or (N,), the error bars are given by (x-dx, x+dx) or (y-dy, y+dy), - if dx or dy has a shape (2, N), the error bars are given by (x-dx[0], x+dx[1]) or (y-dy[0], y+dy[1]). curvePen is the pen used to plot the curve curveStyle is the style used to plot the curve curveSymbol is the symbol used to plot the symbols errorPen is the pen used to plot the error bars errorCap is the size of the error bar caps errorOnTop is a boolean: - if True, plot the error bars on top of the curve, - if False, plot the curve on top of the error bars. """ QwtPlotCurve.__init__(self) if curvePen is None: curvePen = QPen(Qt.NoPen) if curveStyle is None: curveStyle = QwtPlotCurve.Lines if curveSymbol is None: curveSymbol = QwtSymbol() if errorPen is None: errorPen = QPen(Qt.NoPen) self.setData(x, y, dx, dy) self.setPen(curvePen) self.setStyle(curveStyle) self.setSymbol(curveSymbol) self.errorPen = errorPen self.errorCap = errorCap self.errorOnTop = errorOnTop
def __init__(self, parent=None): QtGui.QMainWindow.__init__(self, parent) self.ui=Ui_MainWindow() self.ui.setupUi(self) # connect methods to buttons' click signals self.ui.wakeUpButton.clicked.connect(self.wakeUp) self.ui.stopButton.clicked.connect(self.stop) self.ui.closeButton.clicked.connect(self.close) self.ui.saveButton.clicked.connect(self.save) self.ui.immediateButton.clicked.connect(self.immediate) self.ui.finalButton.clicked.connect(self.final) self.ui.fitButton.clicked.connect(self.fit) self.ui.action_Save_Ctrl_S.triggered.connect(self.save) self.ui.action_Quit_Ctrl_Q.triggered.connect(self.close) self.ui.actionManual.triggered.connect(self.manual) self.ui.actionAbout.triggered.connect(self.about) # initialize an empty curve for the plot widget self.curve = QwtPlotCurve() self.curve.attach(self.ui.qwtPlot) # expEYESdetection and initialization try: self.p = ej.open() assert(self.p.fd) self.setWindowTitle("expEYES Junior found on port {}".format( self.p.fd.port )) except: self.setWindowTitle("ERROR: expEYES Junior NOT FOUND!") self.wakeUpButton.setEnabled(False) # custom properties self.isImmediate=True return
def __init__(self, parent=None): """ Constructor: creates an instance of MyWindow """ ######################################### # Necessary actions, which must be done # # for any project # ######################################### # first, calling the ancestor's creator QtGui.QMainWindow.__init__(self, parent) # get the User Interface from the module UI_p1 self.ui=Ui_MainWindow() # initialize the user interface self.ui.setupUi(self) ######################################### # Custom actions, which can be written # # in other ways for other projects. # ######################################### # aliases for some parts of the user interface self.plotWidget = self.ui.qwtPlot self.measureButton = self.ui.measureButton self.closeButton = self.ui.closeButton # connect methods to buttons' click signals self.measureButton.clicked.connect(self.measure) self.closeButton.clicked.connect(self.close) # initialize an empty curve for the plot widget self.curve = QwtPlotCurve() self.curve.attach(self.plotWidget) # initialize the driver for expEYES Junior self.p = ej.open() return
def create_log_plot(): plot = QwtPlot('LogCurveDemo.py (or how to handle -inf values)') plot.enableAxis(QwtPlot.xBottom) plot.setAxisScaleEngine(QwtPlot.yLeft, QwtLogScaleEngine()) curve = QwtPlotCurve() curve.setRenderHint(QwtPlotCurve.RenderAntialiased) pen = QPen(Qt.magenta) pen.setWidth(1.5) curve.setPen(pen) curve.attach(plot) x = np.arange(0.0, 10.0, 0.1) y = 10 * np.cos(x)**2 - .1 print("y<=0:", y <= 0) curve.setData(x, y) plot.replot() return plot
def __init__(self, *args): QMainWindow.__init__(self, *args) self.plot = QwtPlot(self) self.plot.setTitle("A Simple Map Demonstration") self.plot.setCanvasBackground(Qt.white) self.plot.setAxisTitle(QwtPlot.xBottom, "x") self.plot.setAxisTitle(QwtPlot.yLeft, "y") self.plot.setAxisScale(QwtPlot.xBottom, 0.0, 1.0) self.plot.setAxisScale(QwtPlot.yLeft, 0.0, 1.0) self.setCentralWidget(self.plot) # Initialize map data self.count = self.i = 1000 self.xs = np.zeros(self.count, np.float) self.ys = np.zeros(self.count, np.float) self.kappa = 0.2 self.curve = QwtPlotCurve("Map") self.curve.attach(self.plot) self.curve.setSymbol(QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.red), QPen(Qt.blue), QSize(5, 5))) self.curve.setPen(QPen(Qt.cyan)) toolBar = QToolBar(self) self.addToolBar(toolBar) # 1 tick = 1 ms, 10 ticks = 10 ms (Linux clock is 100 Hz) self.ticks = 10 self.tid = self.startTimer(self.ticks) self.timer_tic = None self.user_tic = None self.system_tic = None self.plot.replot()
def do_compare(self): print('in zoomwin do_compare') if self._compare_max: self.stop_compare_max() self._compare_max = False else: self._max_envelop = self._y_values self._min_envelop = self._y_values self._max_crv = QwtPlotCurve('Zoomed max curve') self._max_crv.attach(self._plotter) self._min_crv = QwtPlotCurve('Zoomed min curve') self._min_crv.attach(self._plotter) self._max_crv.setData(x_values, self._max_envelop) self._min_crv.setData(x_values, self._min_envelop) self._compare_max = True self.reset_max()
def __init__(self, *args): colors = [ Qt.red, Qt.darkRed, Qt.green, Qt.darkGreen, Qt.blue, Qt.darkBlue, Qt.cyan, Qt.darkCyan, Qt.magenta, Qt.darkMagenta, Qt.yellow, Qt.darkYellow, Qt.gray, Qt.darkGray, Qt.lightGray, Qt.black ] QwtPlot.__init__(self, *args) self.setCanvasBackground(Qt.white) self.alignScales() # grid self.grid = QwtPlotGrid() self.grid.attach(self) self.grid.setPen(QPen(Qt.black, 0, Qt.DotLine)) # set titles self.setTitle("Gráfico") self.setAxisTitle(QwtPlot.xBottom, 'Tempo [hh:mm:ss] -->') self.setAxisTitle(QwtPlot.yLeft, 'Nível [mm] -->') """Habilita e denomina eixo Y2""" self.enableAxis(QwtPlot.yRight) self.setAxisTitle(QwtPlot.yRight, '<-- Temp. [ºC]') self.nplots = 16 self.Plots = np.array([]) self.Data = np.array([]) for i in range(self.nplots): self.Plots = np.append(self.Plots, QwtPlotCurve()) self.Plots[i].setPen(QPen(colors[i])) self.Plots[i].attach(self) """define como valor plotado será escrito no eixo x""" self.setAxisScaleDraw(QwtPlot.xBottom, TimeScaleDraw()) self.Data = np.append(self.Data, dataclass()) """Os índices pares se referem à plots no eixo Y1, e os índices ímpares são ligados ao eixo Y2""" if divmod(i, 2)[1] == 1: self.Plots[i].setYAxis(QwtPlot.yRight) self.Plots[i].setData(self.Data[i].x, self.Data[i].y) # legend #self.legend = QwtLegend #QwtLegend().setFrameStyle(QFrame.Box) #self.insertLegend(QwtLegend().setFrameStyle(QFrame.Box), QwtPlot.BottomLegend) self.insertLegend(QwtLegend(), QwtPlot.BottomLegend) # replot self.replot() # zoom # self.zoomer = QwtPlotZoomer(QwtPlot.xBottom, # QwtPlot.yLeft, # QwtPicker.DragSelection, # QwtPicker.AlwaysOn, # self.canvas()) # # self.zoomer.setRubberBandPen(QPen(Qt.green)) self.startTimer(50)
def createCurve(self, x, y, colour): curve = QwtPlotCurve() colour = QColor(colour) curve.setPen(colour) curve.setData(x, y) curve.attach(self.plot) #self.plot.replot() self.curves.append(curve)
def setData(self, *args): if len(args) == 1: QwtPlotCurve.setData(self, *args) return x, y = args[:2] if len(args) > 2: self.symbolSizes = args[2] self.__x = numpy.asarray(x, numpy.float) if len(self.__x.shape) != 1: raise RuntimeError('len(asarray(x).shape) != 1') self.__y = numpy.asarray(y, numpy.float) if len(self.__y.shape) != 1: raise RuntimeError('len(asarray(y).shape) != 1') if len(self.__x) != len(self.__y): raise RuntimeError('len(asarray(x)) != len(asarray(y))') QwtPlotCurve.setData(self, self.__x, self.__y)
def __init__(self, *args): QFrame.__init__(self, *args) self.xMap = QwtScaleMap() self.xMap.setScaleInterval(-0.5, 10.5) self.yMap = QwtScaleMap() self.yMap.setScaleInterval(-1.1, 1.1) # frame style self.setFrameStyle(QFrame.Box | QFrame.Raised) self.setLineWidth(2) self.setMidLineWidth(3) # calculate values self.x = np.arange(0, 10.0, 10.0/27) self.y = np.sin(self.x)*np.cos(2*self.x) # make curves with different styles self.curves = [] self.titles = [] # curve 2 self.titles.append('Style: Lines, Symbol: None') curve = QwtPlotCurve() curve.setPen(QPen(Qt.darkBlue)) curve.setStyle(QwtPlotCurve.Lines) self.curves.append(curve) # attach data, using Numeric for curve in self.curves: curve.setData(self.x, self.y)
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()
def __init__(self, *args): QwtPlot.__init__(self, *args) self.insertLegend(QwtLegend(), QwtPlot.RightLegend) self.enableAxis(self.xBottom) # insert a few curves self.Alpha = QwtPlotCurve('Alpha') self.Alpha.setPen(QPen(Qt.red)) self.Alpha.attach(self) self.Epsilon = QwtPlotCurve('Epsilon') self.Epsilon.setPen(QPen(Qt.blue)) self.Epsilon.attach(self) # initialize the data self.Alpha.setData([0], [0]) self.Epsilon.setData([0], [0]) # replot self.replot()
def create_log_plot(): plot = QwtPlot('LogCurveDemo.py (or how to handle -inf values)') plot.enableAxis(QwtPlot.xBottom) plot.setAxisScaleEngine(QwtPlot.yLeft, QwtLogScaleEngine()) curve = QwtPlotCurve() curve.setRenderHint(QwtPlotCurve.RenderAntialiased) pen = QPen(Qt.magenta) pen.setWidth(1.5) curve.setPen(pen) curve.attach(plot) x = np.arange(0.0, 10.0, 0.1) y = 10*np.cos(x)**2-.1 print("y<=0:", y<=0) curve.setData(x, y) plot.replot() return plot
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 pbServerClicked(self): if self.ServerActive == 0: self.N = self.sbNsig.value() self.Hist = int(self.edHist.text().__str__()) self.pbStartServer.setText('Stop Server') self.ServerActive = 1 self.plot = dataPlot(self.N) self.plot.resize(800, 500) self.plot.show() self.timebase = [] self.x = [] self.c = [] for n in range(0, self.N): self.x.append([]) cv = QwtPlotCurve() pen = QPen(QColor(self.colors[n % 8])) pen.setWidth(WIDTH) cv.setPen(pen) cv.setData([], []) self.c.append(cv) self.c[n].attach(self.plot) self.timer = QtCore.QTimer() self.timer.timeout.connect(self.pltRefresh) refTimer = self.sbRefT.value() self.timer.start(refTimer) self.th = rcvServer(self) self.th.start() else: self.pbStartServer.setText('Start Server') self.ServerActive = 0 self.stopServer()
def __init__(self, *args): QwtPlot.__init__(self, *args) self.setCanvasBackground(Qt.white) # Initialize data self.x = [0] self.y = [0] self.setTitle("A Moving QwtPlot Demonstration") self.insertLegend(QwtLegend(), QwtPlot.BottomLegend); self.curveR = QwtPlotCurve("Data Moving Right") self.curveR.attach(self) self.curveR.setPen(QPen(Qt.red)) self.setAxisTitle(QwtPlot.xBottom, "Time (seconds)") self.setAxisTitle(QwtPlot.yLeft, "Values") self.startTimer(400) self.phase = 0.0
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, database, parent=None): super().__init__(parent) self.db = database self.updateTimer = QTimer(self) self.updateTimer.start(5000) self.plot = QwtPlot() self.curve = QwtPlotCurve() self.curve.attach(self.plot) self.plot.resize(1000, 1000) self.plot.show() self.plot.setAxisScaleDraw(QwtPlot.xBottom, DateTimeTimeScaleDraw()) axisFont = QFont("Helvetica", 11, QFont.Bold) titleFont = QFont("Helvetica", 12, QFont.Bold) xTitle = QwtText() xTitle.setText("Time") xTitle.setFont(axisFont) self.plot.setAxisTitle(self.plot.xBottom, xTitle) self.yTitle = QwtText() self.yTitle.setFont(axisFont) self.plot.setAxisTitle(self.plot.yLeft, self.yTitle) self.titleText = QwtText() self.titleText.setFont(titleFont) self.plot.setTitle(self.titleText) mainLayout = QHBoxLayout() mainLayout.addWidget(self.plot) self.setLayout(mainLayout) self.plot.show() self.results = [] self.batchID = None
def initQwtCurves(self): #BVP# self.bio_graph.bvp_plot.enableAxis(2, 0) self.bio_graph.bvp_plot.curve = QwtPlotCurve() self.bio_graph.bvp_plot.curve.setPen(QPen(Qt.darkBlue)) self.bio_graph.bvp_plot.curve.setStyle(QwtPlotCurve.Lines) self.bio_graph.bvp_plot.curve.setRenderHint( QwtPlotItem.RenderAntialiased) self.bio_graph.bvp_plot.curve.setPen(QPen(Qt.green)) self.bio_graph.bvp_plot.curve.attach(self.bio_graph.bvp_plot) self.bio_graph.bvp_plot.setAutoReplot(False) #GSR# self.bio_graph.gsr_plot.enableAxis(2, 0) self.bio_graph.gsr_plot.curve = QwtPlotCurve() self.bio_graph.gsr_plot.curve.setPen(QPen(Qt.darkBlue)) self.bio_graph.gsr_plot.curve.setStyle(QwtPlotCurve.Lines) self.bio_graph.gsr_plot.curve.setRenderHint( QwtPlotItem.RenderAntialiased) self.bio_graph.gsr_plot.curve.setPen(QPen(Qt.green)) self.bio_graph.gsr_plot.curve.attach(self.bio_graph.gsr_plot) self.bio_graph.gsr_plot.setAutoReplot(False) #TMP# self.bio_graph.tmp_plot.enableAxis(2, 0) self.bio_graph.tmp_plot.curve = QwtPlotCurve() self.bio_graph.tmp_plot.curve.setPen(QPen(Qt.darkBlue)) self.bio_graph.tmp_plot.curve.setStyle(QwtPlotCurve.Lines) self.bio_graph.tmp_plot.curve.setRenderHint( QwtPlotItem.RenderAntialiased) self.bio_graph.tmp_plot.curve.setPen(QPen(Qt.green)) self.bio_graph.tmp_plot.curve.attach(self.bio_graph.tmp_plot) self.bio_graph.tmp_plot.setAutoReplot(False) #ACC# self.bio_graph.acc_plot.enableAxis(2, 0) self.bio_graph.acc_plot.curve1 = QwtPlotCurve() self.bio_graph.acc_plot.curve1.setPen(QPen(Qt.darkBlue)) self.bio_graph.acc_plot.curve1.setStyle(QwtPlotCurve.Lines) self.bio_graph.acc_plot.curve1.setRenderHint( QwtPlotItem.RenderAntialiased) self.bio_graph.acc_plot.curve1.setPen(QPen(Qt.red)) self.bio_graph.acc_plot.curve1.attach(self.bio_graph.acc_plot) self.bio_graph.acc_plot.curve2 = QwtPlotCurve() self.bio_graph.acc_plot.curve2.setPen(QPen(Qt.darkBlue)) self.bio_graph.acc_plot.curve2.setStyle(QwtPlotCurve.Lines) self.bio_graph.acc_plot.curve2.setRenderHint( QwtPlotItem.RenderAntialiased) self.bio_graph.acc_plot.curve2.setPen(QPen(Qt.magenta)) self.bio_graph.acc_plot.curve2.attach(self.bio_graph.acc_plot) self.bio_graph.acc_plot.curve3 = QwtPlotCurve() self.bio_graph.acc_plot.curve3.setPen(QPen(Qt.darkBlue)) self.bio_graph.acc_plot.curve3.setStyle(QwtPlotCurve.Lines) self.bio_graph.acc_plot.curve3.setRenderHint( QwtPlotItem.RenderAntialiased) self.bio_graph.acc_plot.curve3.setPen(QPen(Qt.cyan)) self.bio_graph.acc_plot.curve3.attach(self.bio_graph.acc_plot) self.bio_graph.acc_plot.setAutoReplot(False)
def __init__(self, *args): QwtPlot.__init__(self, *args) # make a QwtPlot widget self.plotLayout().setCanvasMargin(0) self.plotLayout().setAlignCanvasToScales(1) self.setTitle('QwtImagePlot: (un)zoom & (un)hide') # set axis titles self.setAxisTitle(QwtPlot.xBottom, 'time (s)') self.setAxisTitle(QwtPlot.yLeft, 'frequency (Hz)') # insert a few curves self.cSin = QwtPlotCurve('y = pi*sin(x)') self.cCos = QwtPlotCurve('y = 4*pi*sin(x)*cos(x)**2') self.cSin.attach(self) self.cCos.attach(self) # set curve styles self.cSin.setPen(QPen(Qt.green, 2)) self.cCos.setPen(QPen(Qt.black, 2)) self.xzoom_loc = None self.yzoom_loc = None self.xpos = None self.ypos = None # attach a grid grid = QwtPlotGrid() grid.attach(self) grid.setPen(Qt.black, 0, Qt.DotLine) # create zoom curve self.zoom_outline = QwtPlotCurve() self.zoom_outline.setStyle(QwtPlotCurve.Lines) # create and initialize an image display self.plotImage = QwtPlotImage(self) self.plotImage.attach(self) self.gain = 2.0 self.updateDisplay() self.zoomStack = [] self.spy = Spy(self.canvas()) self.prev_xpos = None self.prev_ypos = None # self.connect(self, Qt.SIGNAL("legendClicked(QwtPlotItem*)"), # self.toggleVisibility) self.spy.MouseMove.connect(self.onmouseMoveEvent) self.spy.MousePress.connect(self.onmousePressEvent) self.spy.MouseRelease.connect(self.onmouseReleaseEvent)
class DataPlot(QwtPlot): def __init__(self, *args): QwtPlot.__init__(self, *args) self.setCanvasBackground(Qt.white) # Initialize data self.x = [0] self.y = [0] self.setTitle("A Moving QwtPlot Demonstration") self.insertLegend(QwtLegend(), QwtPlot.BottomLegend); self.curveR = QwtPlotCurve("Data Moving Right") self.curveR.attach(self) self.curveR.setPen(QPen(Qt.red)) self.setAxisTitle(QwtPlot.xBottom, "Time (seconds)") self.setAxisTitle(QwtPlot.yLeft, "Values") self.startTimer(400) self.phase = 0.0 #self.setAlignCanvasToScales(0.5,0.2) def timerEvent(self, e): if self.phase > np.pi - 0.0001: self.phase = 0.0 # y moves from left to right: # shift y array right and assign new value y[0] self.y.append(self.phase+5*random.random()) self.x.append(self.phase*3+0.4*random.random()) # z moves from right to left: # Shift z array left and assign new value to z[n-1]. self.curveR.setData(self.x, self.y) self.replot() self.phase += np.pi*0.0
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 pbServerClicked(self): if self.ServerActive == 0: self.N = self.sbNsig.value() self.Hist = int(self.edHist.text().__str__()) self.pbStartServer.setText('Stop Server') self.ServerActive = 1 self.plot = dataPlot(self.N) self.plot.resize(800, 800) self.plot.show() self.x = [] self.c = [] for n in range(0, self.N): self.x.append([]) for n in range(0, int(self.N / 2)): cv = QwtPlotCurve() pen = QPen(QColor(self.colors[n])) cv.setPen(pen) cv.setData([], []) self.c.append(cv) self.c[n].attach(self.plot) if not (self.ckAutoscale.isChecked()): self.xmin = float(self.edXmin.text().__str__()) self.xmax = float(self.edXmax.text().__str__()) self.ymin = float(self.edYmin.text().__str__()) self.ymax = float(self.edYmax.text().__str__()) self.timer = QtCore.QTimer() self.timer.timeout.connect(self.pltRefresh) refTimer = self.sbRefT.value() self.timer.start(refTimer) self.th = rcvServer(self) self.th.start() else: self.pbStartServer.setText('Start Server') self.ServerActive = 0 self.stopServer()
class MyWindow(QtGui.QMainWindow): """ This class implements a derivative of PyQt4.QtGui.QMainWindow, a complete application window, which can feature menus, submenus, status bar, etc. In this example, it uses few of those features. """ def __init__(self, parent=None): """ Constructor: creates an instance of MyWindow """ ######################################### # Necessary actions, which must be done # # for any project # ######################################### # first, calling the ancestor's creator QtGui.QMainWindow.__init__(self, parent) # get the User Interface from the module UI_p1 self.ui=Ui_MainWindow() # initialize the user interface self.ui.setupUi(self) ######################################### # Custom actions, which can be written # # in other ways for other projects. # ######################################### # aliases for some parts of the user interface self.plotWidget = self.ui.qwtPlot self.measureButton = self.ui.measureButton self.closeButton = self.ui.closeButton self.saveButton = self.ui.saveButton # connect methods to buttons' click signals self.measureButton.clicked.connect(self.measure) self.closeButton.clicked.connect(self.close) self.saveButton.clicked.connect(self.save) # initialize an empty curve for the plot widget self.curve = QwtPlotCurve() self.curve.attach(self.plotWidget) # initialize the driver for expEYES Junior # prevent an error if the box is not detected try: self.p = ej.open() assert(self.p.fd) self.setWindowTitle("expEYES Junior found on port {}".format( self.p.fd.port )) except: self.setWindowTitle("ERROR: expEYES Junior NOT FOUND!") self.measureButton.setEnabled(False) return def measure(self): """ This is a custom method to connect to the button for measurements. There is no need for another custom method, since the method "close" is already inherited from the ancestor class. """ self.t, self.v = self.p.capture(1,1000,200) self.curve.setData(self.t, self.v, len(self.t)) # display the result self.plotWidget.replot() # activate the save widget self.saveButton.setEnabled(True) return def save(self): """ save data into a file named "data.csv" """ with open("data.csv", "w") as outfile: for i in range(len(self.t)): outfile.write("{} {}\n".format(self.t[i], self.v[i])) delay=2000 # 2000 ms = 2 seconds self.ui.statusbar.showMessage("saved data to file data.csv",delay) return
def __init__(self, title, xdata, ydata, style, symbol=None, *args): super(BMPlot, self).__init__(*args) self.setMinimumSize(200, 200) self.setTitle(title) self.setAxisTitle(QwtPlot.xBottom, 'x') self.setAxisTitle(QwtPlot.yLeft, 'y') curve = QwtPlotCurve() curve.setPen(QPen(get_curve_color())) curve.setStyle(style) curve.setRenderHint(QwtPlotCurve.RenderAntialiased) if symbol is not None: curve.setSymbol(symbol) curve.attach(self) curve.setData(xdata, ydata) self.replot()
def __init__(self, *args): QWidget.__init__(self, *args) layout = QGridLayout(self) # try to create a plot for SciPy arrays # make a curve and copy the data numpy_curve = QwtPlotCurve('y = lorentzian(x)') x = np.arange(0.0, 10.0, 0.01) y = lorentzian(x) numpy_curve.setData(x, y) # here, we know we can plot NumPy arrays numpy_plot = QwtPlot(self) numpy_plot.setTitle('numpy array') numpy_plot.setCanvasBackground(Qt.white) numpy_plot.plotLayout().setCanvasMargin(0) numpy_plot.plotLayout().setAlignCanvasToScales(True) # insert a curve and make it red numpy_curve.attach(numpy_plot) numpy_curve.setPen(QPen(Qt.red)) layout.addWidget(numpy_plot, 0, 0) numpy_plot.replot() # create a plot widget for lists of Python floats list_plot = QwtPlot(self) list_plot.setTitle('Python list') list_plot.setCanvasBackground(Qt.white) list_plot.plotLayout().setCanvasMargin(0) list_plot.plotLayout().setAlignCanvasToScales(True) x = drange(0.0, 10.0, 0.01) y = [lorentzian(item) for item in x] # insert a curve, make it red and copy the lists list_curve = QwtPlotCurve('y = lorentzian(x)') list_curve.attach(list_plot) list_curve.setPen(QPen(Qt.red)) list_curve.setData(x, y) layout.addWidget(list_plot, 0, 1) list_plot.replot()
class DataPlot(QwtPlot): 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 alignScales(self): self.canvas().setFrameStyle(QFrame.Box | QFrame.Plain) self.canvas().setLineWidth(1) for i in range(QwtPlot.axisCnt): scaleWidget = self.axisWidget(i) if scaleWidget: scaleWidget.setMargin(0) scaleDraw = self.axisScaleDraw(i) if scaleDraw: scaleDraw.enableComponent(QwtAbstractScaleDraw.Backbone, False) def timerEvent(self, e): if self.phase > np.pi - 0.0001: self.phase = 0.0 # y moves from left to right: # shift y array right and assign new value y[0] self.y = np.concatenate((self.y[:1], self.y[:-1]), 1) self.y[0] = np.sin(self.phase) * (-1.0 + 2.0*random.random()) # z moves from right to left: # Shift z array left and assign new value to z[n-1]. self.z = np.concatenate((self.z[1:], self.z[:1]), 1) self.z[-1] = 0.8 - (2.0 * self.phase/np.pi) + 0.4*random.random() self.curveR.setData(self.x, self.y) self.curveL.setData(self.x, self.z) self.replot() self.phase += np.pi*0.02
class MapDemo(QMainWindow): def __init__(self, *args): QMainWindow.__init__(self, *args) self.plot = QwtPlot(self) self.plot.setTitle("A Simple Map Demonstration") self.plot.setCanvasBackground(Qt.white) self.plot.setAxisTitle(QwtPlot.xBottom, "x") self.plot.setAxisTitle(QwtPlot.yLeft, "y") self.plot.setAxisScale(QwtPlot.xBottom, 0.0, 1.0) self.plot.setAxisScale(QwtPlot.yLeft, 0.0, 1.0) self.setCentralWidget(self.plot) # Initialize map data self.count = self.i = 1000 self.xs = np.zeros(self.count, np.float) self.ys = np.zeros(self.count, np.float) self.kappa = 0.2 self.curve = QwtPlotCurve("Map") self.curve.attach(self.plot) self.curve.setSymbol(QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.red), QPen(Qt.blue), QSize(5, 5))) self.curve.setPen(QPen(Qt.cyan)) toolBar = QToolBar(self) self.addToolBar(toolBar) # 1 tick = 1 ms, 10 ticks = 10 ms (Linux clock is 100 Hz) self.ticks = 10 self.tid = self.startTimer(self.ticks) self.timer_tic = None self.user_tic = None self.system_tic = None self.plot.replot() def setTicks(self, ticks): self.i = self.count self.ticks = int(ticks) self.killTimer(self.tid) self.tid = self.startTimer(ticks) def resizeEvent(self, event): self.plot.resize(event.size()) self.plot.move(0, 0) def moreData(self): if self.i == self.count: self.i = 0 self.x = random.random() self.y = random.random() self.xs[self.i] = self.x self.ys[self.i] = self.y self.i += 1 chunks = [] self.timer_toc = time.time() if self.timer_tic: chunks.append("wall: %s s." % (self.timer_toc-self.timer_tic)) print(' '.join(chunks)) self.timer_tic = self.timer_toc else: self.x, self.y = standard_map(self.x, self.y, self.kappa) self.xs[self.i] = self.x self.ys[self.i] = self.y self.i += 1 def timerEvent(self, e): self.moreData() self.curve.setData(self.xs[:self.i], self.ys[:self.i]) self.plot.replot()
def __insertCurve(self, orientation, color, base): curve = QwtPlotCurve() curve.attach(self) curve.setPen(QPen(color)) curve.setSymbol(QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.gray), QPen(color), QSize(8, 8))) fixed = base * np.ones(10, np.float) changing = np.arange(0, 95.0, 10.0, np.float) + 5.0 if orientation == Qt.Horizontal: curve.setData(changing, fixed) else: curve.setData(fixed, changing)
def __init__(self, *args): QFrame.__init__(self, *args) self.setFrameStyle(QFrame.Box | QFrame.Raised) self.setLineWidth(2) self.setMidLineWidth(3) p = QPalette() p.setColor(self.backgroundRole(), QColor(30, 30, 50)) self.setPalette(p) # make curves and maps self.tuples = [] # curve 1 curve = QwtPlotCurve() curve.setPen(QPen(QColor(150, 150, 200), 2)) curve.setStyle(QwtPlotCurve.Lines) curve.setSymbol(QwtSymbol(QwtSymbol.XCross, QBrush(), QPen(Qt.yellow, 2), QSize(7, 7))) self.tuples.append((curve, QwtScaleMap(0, 100, -1.5, 1.5), QwtScaleMap(0, 100, 0.0, 2*np.pi))) # curve 2 curve = QwtPlotCurve() curve.setPen(QPen(QColor(200, 150, 50), 1, Qt.DashDotDotLine)) curve.setStyle(QwtPlotCurve.Sticks) curve.setSymbol(QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.blue), QPen(Qt.yellow), QSize(5, 5))) self.tuples.append((curve, QwtScaleMap(0, 100, 0.0, 2*np.pi), QwtScaleMap(0, 100, -3.0, 1.1))) # curve 3 curve = QwtPlotCurve() curve.setPen(QPen(QColor(100, 200, 150))) curve.setStyle(QwtPlotCurve.Lines) self.tuples.append((curve, QwtScaleMap(0, 100, -1.1, 3.0), QwtScaleMap(0, 100, -1.1, 3.0))) # curve 4 curve = QwtPlotCurve() curve.setPen(QPen(Qt.red)) curve.setStyle(QwtPlotCurve.Lines) self.tuples.append((curve, QwtScaleMap(0, 100, -5.0, 1.1), QwtScaleMap(0, 100, -1.1, 5.0))) # data self.phase = 0.0 self.base = np.arange(0.0, 2.01*np.pi, 2*np.pi/(USize-1)) self.uval = np.cos(self.base) self.vval = np.sin(self.base) self.uval[1::2] *= 0.5 self.vval[1::2] *= 0.5 self.newValues() # start timer self.tid = self.startTimer(250)
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("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 grid = QwtPlotGrid() grid.attach(self) grid.setPen(QPen(Qt.black, 0, Qt.DotLine)) # 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) 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) self.replot()
def drawSeries(self, painter, xMap, yMap, canvasRect, first, last = -1): """Draw an interval of the curve, including the error bars painter is the QPainter used to draw the curve xMap is the QwtDiMap used to map x-values to pixels yMap is the QwtDiMap used to map y-values to pixels first is the index of the first data point to draw last is the index of the last data point to draw. If last < 0, last is transformed to index the last data point """ if last < 0: last = self.dataSize() - 1 if self.errorOnTop: QwtPlotCurve.drawSeries(self, painter, xMap, yMap, canvasRect, first, last) # draw the error bars painter.save() painter.setPen(self.errorPen) # draw the error bars with caps in the x direction if self.__dx is not None: # draw the bars if len(self.__dx.shape) in [0, 1]: xmin = (self.__x - self.__dx) xmax = (self.__x + self.__dx) else: xmin = (self.__x - self.__dx[0]) xmax = (self.__x + self.__dx[1]) y = self.__y n, i = len(y), 0 lines = [] while i < n: yi = yMap.transform(y[i]) lines.append(QLineF(xMap.transform(xmin[i]), yi, xMap.transform(xmax[i]), yi)) i += 1 painter.drawLines(lines) if self.errorCap > 0: # draw the caps cap = self.errorCap/2 n, i, = len(y), 0 lines = [] while i < n: yi = yMap.transform(y[i]) lines.append( QLineF(xMap.transform(xmin[i]), yi - cap, xMap.transform(xmin[i]), yi + cap)) lines.append( QLineF(xMap.transform(xmax[i]), yi - cap, xMap.transform(xmax[i]), yi + cap)) i += 1 painter.drawLines(lines) # draw the error bars with caps in the y direction if self.__dy is not None: # draw the bars if len(self.__dy.shape) in [0, 1]: ymin = (self.__y - self.__dy) ymax = (self.__y + self.__dy) else: ymin = (self.__y - self.__dy[0]) ymax = (self.__y + self.__dy[1]) x = self.__x n, i, = len(x), 0 lines = [] while i < n: xi = xMap.transform(x[i]) lines.append( QLineF(xi, yMap.transform(ymin[i]), xi, yMap.transform(ymax[i]))) i += 1 painter.drawLines(lines) # draw the caps if self.errorCap > 0: cap = self.errorCap/2 n, i, j = len(x), 0, 0 lines = [] while i < n: xi = xMap.transform(x[i]) lines.append( QLineF(xi - cap, yMap.transform(ymin[i]), xi + cap, yMap.transform(ymin[i]))) lines.append( QLineF(xi - cap, yMap.transform(ymax[i]), xi + cap, yMap.transform(ymax[i]))) i += 1 painter.drawLines(lines) painter.restore() if not self.errorOnTop: QwtPlotCurve.drawSeries(self, painter, xMap, yMap, canvasRect, first, last)
class BodePlot(QwtPlot): 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 showData(self, frequency, amplitude, phase): self.curve1.setData(frequency, amplitude) self.curve2.setData(frequency, phase) def showPeak(self, frequency, amplitude): self.peakMarker.setValue(frequency, amplitude) label = self.peakMarker.label() label.setText('Peak: %4g dB' % amplitude) self.peakMarker.setLabel(label) def show3dB(self, frequency): self.dB3Marker.setValue(frequency, 0.0) label = self.dB3Marker.label() label.setText('-3dB at f = %4g' % frequency) self.dB3Marker.setLabel(label) 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 __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): QwtPlotCurve.__init__(self, *args) self.setRenderHint(QwtPlotItem.RenderAntialiased)
class MyWindow(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QMainWindow.__init__(self, parent) self.ui=Ui_MainWindow() self.ui.setupUi(self) # connect methods to buttons' click signals self.ui.wakeUpButton.clicked.connect(self.wakeUp) self.ui.stopButton.clicked.connect(self.stop) self.ui.closeButton.clicked.connect(self.close) self.ui.saveButton.clicked.connect(self.save) self.ui.immediateButton.clicked.connect(self.immediate) self.ui.finalButton.clicked.connect(self.final) self.ui.fitButton.clicked.connect(self.fit) self.ui.action_Save_Ctrl_S.triggered.connect(self.save) self.ui.action_Quit_Ctrl_Q.triggered.connect(self.close) self.ui.actionManual.triggered.connect(self.manual) self.ui.actionAbout.triggered.connect(self.about) # create a timer self.stopTime=time.time() self.timer=QtCore.QTimer() # connect the timer to the "tick" callback method self.timer.timeout.connect(self.tick) # 20 times per second self.timer.start(50) # initialize an empty curve for the plot widget self.curve = QwtPlotCurve() self.curve.attach(self.ui.qwtPlot) # expEYESdetection and initialization try: self.p = ej.open() assert(self.p.fd) self.setWindowTitle("expEYES Junior found on port {}".format( self.p.fd.port )) except: self.setWindowTitle("ERROR: expEYES Junior NOT FOUND!") self.wakeUpButton.setEnabled(False) # custom properties self.isImmediate=True return def immediate(self): self.isImmediate=True return def final(self): self.isImmediate=False return def wakeUp(self): # get the duration of the experiment in s duration = float(self.ui.durationEdit.text()) if duration < 0.5: # "final" mode is mandatory self.ui.finalButton.setChecked(True) self.isImmediate=False elif duration > 3.5: # "immediate" mode is mandatory self.ui.immediateButton.setChecked(True) self.isImmediate=True self.ui.qwtPlot.setAxisScale(QwtPlot.xBottom, 0, duration) if self.isImmediate: now=time.time() self.t=[] self.v=[] self.curve.setData([],[],0) self.startTime=now self.stopTime=now+duration # now the curve will grow until time.time >= self.stopTime # thanks to self.timer's timeout events else: samples = 1800 # maximum sample number with 8 bit precision # ensure that samples * delay will be slightly bigger than duration delay=1+int(duration*1e6/1800) t, self.v = self.p.capture(1,samples, delay) self.t=[1e-3*date for date in t] # convert ms to s self.curve.setData(self.t, self.v, len(self.t)) return def tick(self): """ Callback for the timeout events """ t=time.time() if t < self.stopTime: v = self.p.get_voltage(1) self.t.append(time.time()-self.startTime) self.v.append(v) self.curve.setData(self.t, self.v, len(self.t)) return def notImplemented(self): msg=QtGui.QMessageBox(QtGui.QMessageBox.Warning,"Sorry", "not yet implemented", ) msg.exec_() return stop=save=fit=manual=about=notImplemented
# -*- coding: utf-8 -*- __author__ = 'Valeriy' from qwt.qt.QtGui import QApplication from qwt import QwtPlot, QwtPlotCurve import numpy as np app = QApplication([]) # x = [1,2,3,4,5,6,7,8,9] # y1 = [3.2, 5.1 ,7.0, 4.24, 4.41, 8.34, 2.21, 5.657, 6.1] x = [] y1 = [] my_plot = QwtPlot("Two curves") curve1 = QwtPlotCurve("Curve 1") my_plot.resize(600, 300) curve1.setData(x, y1) curve1.attach(my_plot) # my_plot.replot() my_plot.show() app.exec_() # SELECT PrepData FROM= Pdata WHERE ((PNameId=2) AND (SNameId = 14) AND (YearId=2012))