From ea8b381c8a2dc01aa461d77c58e9ea1d3ce74dca Mon Sep 17 00:00:00 2001 From: Scott Lawson Date: Mon, 7 Nov 2016 17:43:47 -0800 Subject: [PATCH] Added gui.py module for handling pyqtgraph plots --- python/gui.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 python/gui.py diff --git a/python/gui.py b/python/gui.py new file mode 100644 index 0000000..ef98704 --- /dev/null +++ b/python/gui.py @@ -0,0 +1,46 @@ +from __future__ import print_function +from __future__ import division +import time +import numpy as np +from pyqtgraph.Qt import QtGui +import pyqtgraph as pg + + +class GUI: + plot = [] + curve = [] + + def __init__(self, width=800, height=450, title=''): + self.app = QtGui.QApplication([]) + self.win = pg.GraphicsWindow(title) + self.win.resize(width, height) + self.win.setWindowTitle(title) + + def add_plot(self, title): + self.plot.append(self.win.addPlot(title=title)) + self.curve.append([]) + + def add_curve(self, plot_index, pen=(255, 255, 255)): + self.curve[plot_index].append(self.plot[plot_index].plot(pen=pen)) + + +if __name__ == '__main__': + N = 48 + gui = GUI(title='Test') + + # Sin plot + gui.add_plot(title='Sin Plot') + gui.add_curve(plot_index=0) + gui.win.nextRow() + # Cos plot + gui.add_plot(title='Cos Plot') + gui.add_curve(plot_index=1) + + while True: + t = time.time() + x = np.linspace(t, 2 * np.pi + t, N); + gui.curve[0][0].setData(x=x, y=np.sin(x)) + gui.curve[1][0].setData(x=x, y=np.cos(x)) + gui.app.processEvents() + time.sleep(1.0 / 30.0) +