def __init__(self, sampleinterval, timewindow, size=(600, 350)): # Data stuff self.tick_idx = 0 self._bufsize = int(timewindow / sampleinterval) self.databuffer = collections.deque([0.0] * self._bufsize, self._bufsize) self.x = np.linspace(0.0, timewindow, self._bufsize) self.y = np.zeros(self._bufsize, dtype=np.float) # Candlestick data self.candlestick_item = CandlestickItem() # PyQtGraph stuff self.app = QtGui.QApplication([]) self.plt = pg.plot(title='Plot Viewer') self.plt.resize(*size) self.plt.showGrid(x=True, y=True) self.plt.setLabel('left', 'amplitude', 'V') self.plt.setLabel('bottom', 'time', 's') self.plt.setXRange(0., timewindow) self.plt.setYRange(0., 30) self.curve = self.plt.plot(self.x, self.y, pen=(255, 0, 0)) self.plt.addItem(self.candlestick_item) # QTimer self.timer = QtCore.QTimer() self.timer.timeout.connect(self.updateplot) self.timer.start(1000)
def __init__(self, sampleinterval=2000): """ Monitor System Statistics Input Args: sampleinterval (int) = polling interval for collecting data """ self.sampleinterval = sampleinterval self.data = deque(maxlen=20) self.device_info = info.InformationStatistics() self.app = QtGui.QApplication([]) self.win = pg.GraphicsWindow(title="Monitor System Statistics") self.win.resize(800, 600) self.plot = self.win.addPlot( title='CPU and Swap Mem Usage', axisItems={'bottom': TimeAxisItem(orientation='bottom')}) self.plot.addLegend() self.plot.setLimits(yMin=0, yMax=100, xMin=0) self.plot.showGrid(x=True, y=True) self.plot.setMouseEnabled(False, False) self.plot.setRange(yRange=(0, 100), disableAutoRange=True) # Trying to fix y-axis at 0,100 self.plot.setLabel('left', "Percentage Utilization") self.plot.setLabel('bottom', "Time (s)") self.cpu_stats = self.plot.plot(pen='r', name="CPU Usage") self.swap_mem_stats = self.plot.plot(pen='b', name="Swap Mem Usage") self.time = QtCore.QTime() self.time.start() self.timer = QtCore.QTimer() self.timer.timeout.connect(self.update_plot) self.timer.start(self.sampleinterval)
def initializeGUI(self): """ Initializes the Qt GUI framework and application. """ self.app = QtGui.QApplication(sys.argv) self.imageDisplay = ImageDisplay(self.args["fStart"], self.args["fEnd"], self.args["fInterval"], self.args["fSpeedFactor"], self.imageHandler)
def main(): import sys app = QtGui.QApplication(sys.argv) window = DataViz() window.show() app.exec_() # fixed segfaults at exit: # http://python.6.x6.nabble.com/Application-crash-on-exit-under-Linux-td5067510.html del window del app sys.exit(0)
def __init__(self): self.app = QtGui.QApplication(sys.argv) self.w = gl.GLViewWidget() self.w.setGeometry(0, 0, 1000, 1000) self.w.show() self.w.setWindowTitle('Terrain') self.w.setCameraPosition(distance=50, elevation=8) self.i = 0 self.nsteps = 1 self.ypoints = range(-20, 22, self.nsteps) self.xpoints = range(-20, 22, self.nsteps) self.nfaces = len(self.ypoints) self.tmp = OpenSimplex() self.offset = 0 verts = np.array([[x, y, 1.5 * self.tmp.noise2d(x=n / 5, y=m / 5)] for n, x in enumerate(self.xpoints) for m, y in enumerate(self.ypoints)], dtype=np.float32) faces = [] colors = [] for m in range(self.nfaces - 1): yoff = m * self.nfaces for n in range(self.nfaces - 1): faces.append([ n + yoff, yoff + n + self.nfaces, yoff + n + self.nfaces + 1 ]) faces.append( [n + yoff, yoff + n + 1, yoff + n + self.nfaces + 1]) colors.append([0, 0, 0, 0]) colors.append([0, 0, 0, 0]) faces = np.array(faces) colors = np.array(colors) self.m1 = gl.GLMeshItem( vertexes=verts, faces=faces, faceColors=colors, smooth=False, drawEdges=True, ) self.m1.setGLOptions('additive') self.w.addItem(self.m1)
def __init__(self): self.app = QtGui.QApplication(sys.argv) # Initializes the: # - The data that will be sorted; # - The plot that will display the sorting process; # - The sorter that contains all the sorting algorithms; # Note: # Because the 'Sorter' class is from another file (sorting.py), # this instance needs references to both 'app/plotWidget' variables to update # the graph in real-time (through calls in the middle of the sorting algorithms); self.data = [] self.plotWidget = None self.sorter = None super(VisualSorting, self).__init__() self.initUI()
def open_data(filename): ''' User selects values for rn and I max using the mouse and the database is updated :param filename: full filename of _Rn_raw data ''' # globals needed to communicate with mouse move fcn global count, slope_x, slope_y, steps global vLines, hLines, slope_plots, x, y, vbs, plots, I_max_plots global I_max_x, I_max_y global num_JJ, chip_info, chip_name, dev_name, dev_size global filename_to_save, web_info, web_link global windows, plots, curves web_link = ( "https://nistgov.sharepoint.com/sites/SEG/Shared%20Documents/Forms/AllItems.aspx?viewpath=%2Fsites%2FSEG%2FShared%20Documents%2FForms%2FAllItems%2Easpx&id=%2Fsites%2FSEG%2FShared%20Documents%2FSFQ_circuits%2FMeasurements%2F" ) filename_to_save = filename[0:-8] app = QtGui.QApplication.instance() if app is None: app = QtGui.QApplication(sys.argv) else: pass # same set up as live plot, create all aspects curves = initialization() x, y = lpf.create_data(curves) vbs = lpf.create_vb( plots) # this is new, need to use viewbox to convert coordinates # set up window correctly windows[0].move( 0, 0) # move to other desktop, spyder had been blocking before windows[0].setWindowState(QtCore.Qt.WindowActive) windows[0].raise_() # this will activate the window (yellow flashing on icon) windows[0].activateWindow() # find the number of junctions based on the filename dev_is_sj = re.findall('SJ', filename) # is it a single junction? if len(dev_is_sj) == 1: # yes num_JJ = 1 else: # no num_JJ = 400 # get the chip name filename_split_up = re.split('/', filename) #first, split by components web_info = filename_split_up[-2] filename_split_up = filename_split_up[-1] # get the last section chip_info = re.split('_Rn_raw', filename_split_up) # split the descrtiption chip_info = chip_info[0] chip_info_split = re.split('_', chip_info) chip_name = chip_info_split[0] dev_name = chip_info_split[1] dev_size = chip_info_split[2] print("name: " + chip_name) print("dev: " + dev_name) print("size: " + dev_size) print("num JJ: %s" % num_JJ) # get the data # input file name must use '/', not '\' filename = re.sub('/', '\\\\', filename) # numPy likes double backslashes vals = np.loadtxt(filename) # raw I_np = vals[:, 0] # in format of np.array V_np = vals[:, 1] I = [] V = [] # convert to python array and plot for i in range(0, len(I_np)): I.append(I_np[i]) V.append(V_np[i]) curves[0].setData(I, V, symbolSize=5, symbolBrush='w') # set global vars, to send to mouse click function x[0] = I y[0] = V #detect the spacing steps = I[1] - I[0] # create the cross hairs vLines, hLines = lpf.create_lines(plots) # initialize count and placeholders count = 0 slope_x = [] slope_y = [] I_max_x = [] I_max_y = [] # connect the mouse functions for i in range(0, len(plots)): plots[i].scene().sigMouseClicked.connect(onClick) for i in range(0, len(plots)): plots[i].scene().sigMouseMoved.connect(MouseMoved) # create the blank data to be added to slope_plots = lpf.create_slope_plots(plots) I_max_plots = lpf.create_slope_plots(plots) # use title as instructions plots[0].setTitle("Select two points to find the Rn")
def main(): app = QtGui.QApplication(sys.argv) ex = Example() sys.exit(app.exec_())
def main(): app = QtGui.QApplication(sys.argv) earthModeling = DigitizerGUI() sys.exit(app.exec_())
self.name = '' if dataset is not None: self.setDataset(dataset) def setDataset(self, dataset): model = create_default_model(dataset) self.setModel(model) self.name = '{}:{}'.format(dataset.file.filename, dataset.name) self.setToolTip('Dataset <b>{}</b> [file: {}]'.format( dataset.name, dataset.file.filename)) if __name__ == '__main__': import sys import h5py as h5 app = QtGui.QApplication(sys.argv) window = QtGui.QMainWindow() fd = h5.File('poolroom.h5', 'r') widget1 = HDFDatasetWidget(dataset=fd['/map/nonuniform/tables/players']) widget2 = HDFDatasetWidget(dataset=fd['/data/uniform/ndim/data3d']) widget3 = HDFDatasetWidget() widget3.setDataset(fd['/data/uniform/balls/x']) widget = QtGui.QWidget(window) layout = QtGui.QHBoxLayout(widget) layout.addWidget(widget1) layout.addWidget(widget2) layout.addWidget(widget3) widget.setLayout(layout) window.setCentralWidget(widget) window.show() sys.exit(app.exec_())
def main(): app = QtGui.QApplication(sys.argv) w = MainWindow() w.show() sys.exit(app.exec_())
from candlestick import CandlestickItem import pyqtgraph as pg from pyqtgraph import QtCore, QtGui import tushare as ts # read the sh index from the tushare module shdata = ts.get_hist_data('sh', start='2018-07-01', end='2018-09-09').sort_index() ## construct the candlestick required data structure id_col = [i for i in range(1, shdata.shape[0] + 1)] # rows shdata["id"] = id_col df_col_slice = shdata[["id", "open", "close", "low", "high"]] list_data = df_col_slice.values.tolist() print(list_data) item = CandlestickItem(list_data) plt = pg.plot() plt.addItem(item) plt.setWindowTitle('pyqtgraph example: customGraphicsItem') ## Start Qt event loop unless running in interactive mode or using pyside. if __name__ == '__main__': import sys # QtGui.QApplication.instance().exec_() QtGui.QApplication([]).exec_()
def gui_app(): import sys from pyqtgraph import QtGui app = QtGui.QApplication(sys.argv) yield app
def __init__(self, args, option='camera'): self.args = args self.fpsTime = 0 self.option = option self.app = QtGui.QApplication(sys.argv) self.window = GLViewWidget() self.window.setGeometry(0, 150, 1920, 1080) self.window.setCameraPosition(distance=50, elevation=8) self.window.setWindowTitle("3D Pose Estimation") self.window.show() gx = GLGridItem() gy = GLGridItem() gz = GLGridItem() gx.rotate(90, 0, 1, 0) gy.rotate(90, 1, 0, 0) gx.translate(-10, 0, 0) gy.translate(0, -10, 0) gz.translate(0, 0, -10) self.window.addItem(gx) self.window.addItem(gy) self.window.addItem(gz) self.lines = {} keypoints = [] self.connection = [[0, 1], [1, 2], [2, 3], [0, 4], [4, 5], [5, 6], [0, 7], [7, 8], [8, 9], [9, 10], [8, 11], [11, 12], [12, 13], [8, 14], [14, 15], [15, 16]] self.w, self.h = model_wh(self.args.resize) if self.w > 0 and self.h > 0: self.e = TfPoseEstimator(get_graph_path(self.args.model), target_size=(self.w, self.h), trt_bool=str2bool(self.args.tensorrt)) else: self.e = TfPoseEstimator(get_graph_path(self.args.model), target_size=(432, 368), trt_bool=str2bool(self.args.tensorrt)) print(self.args.option) image, ret_val = PoseEstimation.getframe(self.args.option) self.poseLifting = Prob3dPose( 'lifting/prob_model/prob_model_params.mat') try: keypoints = self.mesh(image) except AssertionError: print("body not in image") keypoints = np.zeros((17, 3)) except Exception: print("General exception") keypoints = np.zeros((17, 3)) # self.lines = {} # self.connection = [ # [13, 16] # ] # p = [] # p.append(keypoints[13]) # p.append(keypoints[16]) # p = np.array(p) finally: self.points = GLScatterPlotItem( pos=np.array(np.array(keypoints)), color=glColor((12, 255, 0)), size=15, ) self.window.addItem(self.points) for n, pts in enumerate(self.connection): self.lines[n] = GLLinePlotItem(pos=np.array( [keypoints[p] for p in pts]), color=glColor((0, 0, 255)), width=3, antialias=True) self.window.addItem(self.lines[n])
def main(): app = QtGui.QApplication(sys.argv) ex = TestClass() ex.show() sys.exit(app.exec_())
def main(): app = QtGui.QApplication(sys.argv) app.setApplicationName('Sinuswave') ex = sinus_wave() sys.exit(app.exec_())
def _create_app(self): self.app = QtGui.QApplication([])
def main(): app = QtGui.QApplication(sys.argv) app.setApplicationName('NETCDF TIME Data') ex = netgui() sys.exit(app.exec_())
class UIChan: class CandlestickItem(pg.GraphicsObject): def __init__(self): pg.GraphicsObject.__init__(self) self.flagHasData = False def set_data(self, data): self.data = data # data must have fields: time, open, close, min, max self.flagHasData = True self.generatePicture() self.informViewBoundsChanged() def generatePicture(self): # pre-computing a QPicture object allows paint() to run much more quickly, # rather than re-drawing the shapes every time. self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen('w')) w = (self.data[1][0] - self.data[0][0]) / 3. for (t, open, close, min, max) in self.data: p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max)) if open > close: p.setBrush(pg.mkBrush('g')) else: p.setBrush(pg.mkBrush('r')) p.drawRect(QtCore.QRectF(t - w, open, w * 2, close - open)) p.end() def paint(self, p, *args): if self.flagHasData: p.drawPicture(0, 0, self.picture) def boundingRect(self): # boundingRect _must_ indicate the entire area that will be drawn on # or else we will get artifacts and possibly crashing. # (in this case, QPicture does all the work of computing the bouning rect for us) return QtCore.QRectF(self.picture.boundingRect()) class BisItem(pg.GraphicsObject): def __init__(self): pg.GraphicsObject.__init__(self) self.flagHasData = False def set_data(self, data): self.data = data # data must have fields: time, open, close, min, max self.flagHasData = True self.generatePicture() self.informViewBoundsChanged() def generatePicture(self): # pre-computing a QPicture object allows paint() to run much more quickly, # rather than re-drawing the shapes every time. self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) for bi in self.data: if bi.biType == 'up': p.setPen(pg.mkPen('r')) p.drawLine(QtCore.QPointF(chan.chanBars[bi.barIndex1].closeIndex, chan.lowBar[chan.chanBars[bi.barIndex1].closeIndex]), QtCore.QPointF( chan.chanBars[bi.barIndex2].closeIndex, chan.highBar[chan.chanBars[bi.barIndex2].closeIndex])) else: p.setPen(pg.mkPen('g')) p.drawLine(QtCore.QPointF(chan.chanBars[bi.barIndex1].closeIndex, chan.highBar[chan.chanBars[bi.barIndex1].closeIndex]), QtCore.QPointF( chan.chanBars[bi.barIndex2].closeIndex, chan.lowBar[chan.chanBars[bi.barIndex2].closeIndex])) p.end() def paint(self, p, *args): if self.flagHasData: p.drawPicture(0, 0, self.picture) def boundingRect(self): # boundingRect _must_ indicate the entire area that will be drawn on # or else we will get artifacts and possibly crashing. # (in this case, QPicture does all the work of computing the bouning rect for us) return QtCore.QRectF(self.picture.boundingRect()) class LinesItem(pg.GraphicsObject): def __init__(self): pg.GraphicsObject.__init__(self) self.flagHasData = False def set_data(self, data): self.data = data # data must have fields: time, open, close, min, max self.flagHasData = True self.generatePicture() self.informViewBoundsChanged() def generatePicture(self): # pre-computing a QPicture object allows paint() to run much more quickly, # rather than re-drawing the shapes every time. self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) for line in self.data: if line.lineType == 'up': p.setPen(pg.mkPen('r')) p.drawLine(QtCore.QPointF(chan.chanBars[line.barIndex1].closeIndex, chan.lowBar[chan.chanBars[line.barIndex1].closeIndex]), QtCore.QPointF( chan.chanBars[line.barIndex2].closeIndex, chan.highBar[chan.chanBars[line.barIndex2].closeIndex])) else: p.setPen(pg.mkPen('g')) p.drawLine(QtCore.QPointF(chan.chanBars[line.barIndex1].closeIndex, chan.highBar[chan.chanBars[line.barIndex1].closeIndex]), QtCore.QPointF( chan.chanBars[line.barIndex2].closeIndex, chan.lowBar[chan.chanBars[line.barIndex2].closeIndex])) p.end() def paint(self, p, *args): if self.flagHasData: p.drawPicture(0, 0, self.picture) def boundingRect(self): # boundingRect _must_ indicate the entire area that will be drawn on # or else we will get artifacts and possibly crashing. # (in this case, QPicture does all the work of computing the bouning rect for us) return QtCore.QRectF(self.picture.boundingRect()) class ZhongshusItem(pg.GraphicsObject): def __init__(self): pg.GraphicsObject.__init__(self) self.flagHasData = False def set_data(self, data): self.data = data # data must have fields: time, open, close, min, max self.flagHasData = True self.generatePicture() self.informViewBoundsChanged() def generatePicture(self): # pre-computing a QPicture object allows paint() to run much more quickly, # rather than re-drawing the shapes every time. self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen('w')) p.setBrush(pg.mkBrush(None)) for zhongshu in self.data: p.drawRect(QtCore.QRectF(chan.chanBars[zhongshu.barIndex1].closeIndex, zhongshu.low, chan.chanBars[ zhongshu.barIndex2].closeIndex - chan.chanBars[zhongshu.barIndex1].closeIndex, zhongshu.high - zhongshu.low)) p.end() def paint(self, p, *args): if self.flagHasData: p.drawPicture(0, 0, self.picture) def boundingRect(self): # boundingRect _must_ indicate the entire area that will be drawn on # or else we will get artifacts and possibly crashing. # (in this case, QPicture does all the work of computing the bouning rect for us) return QtCore.QRectF(self.picture.boundingRect()) class BeiChiItem(pg.GraphicsObject): def __init__(self): pg.GraphicsObject.__init__(self) self.flagHasData = False def set_data(self, data): self.data = data # data must have fields: time, open, close, min, max self.flagHasData = True self.generatePicture() self.informViewBoundsChanged() def generatePicture(self): # pre-computing a QPicture object allows paint() to run much more quickly, # rather than re-drawing the shapes every time. self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen('w',width=15)) p.setPen(pg.mkColor("#FF0000")) p.setBrush(pg.mkBrush(None)) for i in self.data: p.drawPoint(i, chan.closeBar[i]) p.end() def paint(self, p, *args): if self.flagHasData: p.drawPicture(0, 0, self.picture) def boundingRect(self): # boundingRect _must_ indicate the entire area that will be drawn on # or else we will get artifacts and possibly crashing. # (in this case, QPicture does all the work of computing the bouning rect for us) return QtCore.QRectF(self.picture.boundingRect()) class DateAxis(pg.AxisItem): def __init__(self, dates, *args, **kwargs): pg.AxisItem.__init__(self, *args, **kwargs) self.x_values = list(range(len(dates))) # self.x_strings = [] # for i in dates: # self.x_strings.append(i.strftime('%Y%m%d')) self.x_strings = dates def tickStrings(self, values, scale, spacing): strings = [] if(len(values)==0): return strings rng = max(values)-min(values) for v in values: vs = v* scale if vs in self.x_values: if rng >= 100: vstr = self.x_strings[np.abs(self.x_values-vs).argmin()].strftime('%Y%m%d') else: vstr = self.x_strings[np.abs(self.x_values-vs).argmin()].strftime('%Y%m%d,%H:%M') else: vstr = "" strings.append(vstr) return strings global data import sys sys.path.append('./') sys.path.append('../') import pandas as pd class ValuesParser: def __init__(self,dataframe): self.Data = [data['open'].tolist(),data['high'].tolist(),data['low'].tolist(),data['close'].tolist(),data['volume'].tolist()] self.Times= data.index.tolist() data = pd.DataFrame.from_csv('rb1705_year.csv')[10000:12100] data = ValuesParser(data) global dataToNow #dataToNow = w.wst(code, "last", data.Times[-1], nowTime, "") dataToNow = [] quotes = [] for i in range(len(data.Times)): quotes.append([i, data.Data[0][i], data.Data[3][i], data.Data[2][i], data.Data[1][i]]) global chan #chan = Chan(data.Data[0], data.Data[1], data.Data[2],data.Data[3], data.Data[4], data.Times) chan = Chan([],[],[],[],[],[]) print(len(data.Times)) start = 1500 for tick in range(0, start): chan.append(data.Data[0][tick], data.Data[1][tick], data.Data[2][tick], data.Data[3][tick], data.Data[4][tick], data.Times[tick]) for tick in range(start, len(data.Times)): chan.append(data.Data[0][tick], data.Data[1][tick], data.Data[2][tick], data.Data[3][tick], data.Data[4][tick], data.Times[tick]) chan.barsMerge() chan.findFenxing() chan.findBi() chan.findLines() chan.findZhongshus() chan.calculate_ta() chan.findBiZhongshus() chan.macdSeparate() chan.findTrendLines() chan.decisionBi() #chan.plotBuySell() chan.plotBeichi() #chan.plotBiZhongshu() plt.show() print(len(chan.dingbeichi)) app = QtGui.QApplication([]) win = pg.GraphicsWindow() #win = ApplicationWindow() win.setWindowTitle('行情+缠论') label = pg.LabelItem(justify = "center") win.addItem(label) axis = DateAxis(data.Times,orientation='bottom') p1 = win.addPlot(row=1, col=0,axisItems = {'bottom':axis}) p2 = win.addPlot(row=2, col=0,axisItems = {'bottom':axis}) p2.setXLink(p1) p2.plot(x = list(range(len(data.Times))),y = chan.diff,pen = 'w') p2.plot(x = list(range(len(data.Times))),y = chan.dea,pen = 'y') hLine = pg.InfiniteLine(angle=0, movable=False) hLine.setPos(0) p2.addItem(hLine, ignoreBounds=True) macdPositive = [] macdNegetive = [] for i in chan.macd: if i>=0: macdPositive.append(i) macdNegetive.append(0) else: macdPositive.append(0) macdNegetive.append(i) curve0 = p2.plot(x = list(range(len(data.Times))),y = np.zeros(len(data.Times))) curve1 = p2.plot(x = list(range(len(data.Times))),y = macdPositive, pen = 'w') curve2 = p2.plot(x = list(range(len(data.Times))),y = macdNegetive, pen = 'w') itemFill1 = pg.FillBetweenItem(curve0,curve1,pg.mkBrush('r')) itemFill2 = pg.FillBetweenItem(curve0,curve2,pg.mkBrush('g')) p2.addItem(itemFill1) p2.addItem(itemFill2) #win.addItem(label) #text = pg.TextItem('test',anchor=(0,1)) # p1.addItem(text) itemK = CandlestickItem() itemK.set_data(quotes) itemBi = BisItem() itemBi.set_data(chan.bis) itemLine = LinesItem() itemLine.set_data(chan.lines) itemZhongshu = ZhongshusItem() #itemZhongshu.set_data(chan.zhongshus) itemZhongshu.set_data(chan.biZhongshus) itemDiBeiChi = BeiChiItem() itemDiBeiChi.set_data(chan.dibeichi) itemDingBeiChi = BeiChiItem() itemDingBeiChi.set_data(chan.dingbeichiLine) itemTrendDiBeiChi = BeiChiItem() itemTrendDiBeiChi.set_data(chan.trendDibeichi) itemTrendDingBeiChi = BeiChiItem() itemTrendDingBeiChi.set_data(chan.trendDingbeichi) p1.plot() p1.addItem(itemK) p1.addItem(itemBi) p1.addItem(itemLine) p1.addItem(itemZhongshu) p1.addItem(itemDiBeiChi) p1.addItem(itemDingBeiChi) p1.addItem(itemTrendDiBeiChi) p1.addItem(itemTrendDingBeiChi) p1.showGrid(x=True,y=True) #p1.setWindowTitle('pyqtgraph example: customGraphicsItem') # cross hair vLine = pg.InfiniteLine(angle=90, movable=False) hLine = pg.InfiniteLine(angle=0, movable=False) p1.addItem(vLine, ignoreBounds=True) p1.addItem(hLine, ignoreBounds=True) vb1 = p1.vb vb2 = p2.vb def mouseMoved(evt): pos = evt[0] # using signal proxy turns original arguments into a tuple if p1.sceneBoundingRect().contains(pos): mousePoint = vb1.mapSceneToView(pos) index = int(mousePoint.x()) if index > 0 and index < len(quotes): label.setText("<span style='font-size: 12pt'>date=%s, <span style='color: red'>open=%0.01f</span>, <span style='color: green'>close=%0.01f\n, high = %0.01f, low = %0.01f</span>" % (data.Times[index].strftime('%Y%m%d,%H:%M'), quotes[index][1], quotes[index][2], quotes[index][3], quotes[index][4])) vLine.setPos(mousePoint.x()) hLine.setPos(mousePoint.y()) setYRange() def setYRange(): r = vb1.viewRange() xmin = math.floor(r[0][0]) xmax = math.ceil(r[0][1]) #fix index <0 bug xmax = max(0,xmax-xmin) xmin = max(0,xmin) xmin = min(xmin,len(data.Times)) xmax = min(xmax,len(data.Times)) xmax = max(xmin,xmax) if(xmin==xmax): return highBound1 = max(data.Data[1][xmin:xmax]) lowBound1 = min(data.Data[2][xmin:xmax]) p1.setRange(yRange=(lowBound1,highBound1)) highBound2 = max(chan.diff[xmin:xmax]) lowBound2 = min(chan.diff[xmin:xmax]) p2.setRange(yRange=(lowBound2,highBound2)) proxy = pg.SignalProxy(p1.scene().sigMouseMoved, rateLimit=60, slot=mouseMoved) aaa = 0 def update(): global itemK,itemBi,itemLine,itemZhongshu dataToNowDf = DataFrame(index=dataToNow.Times,data = dataToNow.Data[0],columns=['price']) dataToNowDf = dataToNowDf.between_time('9:30','11:30').append(dataToNowDf.between_time('13:00','15:00')) a = dataToNowDf.resample('30T',how = {'price':'ohlc'},label='right').dropna() for i in a.iterrows(): data.Times.append(i[0].to_datetime()) data.Data[0].append(i[1]['price']['open']) data.Data[1].append(i[1]['price']['high']) data.Data[2].append(i[1]['price']['low']) data.Data[3].append(i[1]['price']['close']) data.Data[4].append(0) quotes = [] for i in range(len(data.Times)): quotes.append([i, data.Data[0][i], data.Data[3][i], data.Data[2][i], data.Data[1][i]]) chan = Chan(data.Data[0], data.Data[1], data.Data[2], data.Data[3], data.Data[4], data.Times) chan.barsMerge() chan.findFenxing() chan.findBi() chan.findLines() chan.findZhongshus() chan.calculate_ta() a += 1 itemK.set_data(quotes) # itemBi.set_data(chan.bis) # itemLine.set_data(chan.lines) # itemZhongshu.set_data(chan.zhongshus) app.processEvents() ## force complete redraw for every plot #timer = QtCore.QTimer() #timer.timeout.connect(update) #timer.start(100000) # Start Qt event loop unless running in interactive mode or using pyside. if __name__ == '__main__': import sys if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): # threadFeedData = threading.Thread(target=feedData, name='threadFeedData') # threadFeedData.start() # threadFeedData.join() QtGui.QApplication.instance().exec_()
def main(): """The main.""" app = QtGui.QApplication(sys.argv) ex = vplottercontroller() sys.exit(app.exec_())
def start_gui(self): self.app = QtGui.QApplication(sys.argv) self.w = DemoWindow() self.w.graph.w1.textButton.clicked.connect(self.setSlider) self.w.show() self.app.exec_()
def main(): app = QtGui.QApplication(sys.argv) ex = Radiodemo() ex.show() sys.exit(app.exec_())
def main(): app = QtGui.QApplication(sys.argv) EarthModeling = UI() sys.exit(app.exec_())
# from PyQt5 import QtWidgets # from pyqtgraph import QtGui as QtWidgets from pyqtgraph import QtGui as QtWidgets import HSA if __name__ == "__main__": qapp = QtWidgets.QApplication([]) app = HSA.HSA() qapp.exec()
def main(): app = QtGui.QApplication(sys.argv) app.setApplicationName('MCE TIME Data') ex = mcegui() sys.exit(app.exec_())
def init_pygame(): # initialize pygame pygame.init() js = pygame.joystick.Joystick(0) # initialzie joystick js.init() jsInit = js.get_init() jsId = js.get_id() print(js.get_name() + "Joystick ID: %d Init status: %s" % (jsId, jsInit)) numAxes = js.get_numaxes() print("Please press A to start, press the xBox button to quit") # waiting for initial keys while (True): pygame.event.pump() keys = [js.get_button(i) for i in range(js.get_numbuttons())] if keys[0] != 0: break if keys[10] != 0: sys.exit() ### START QtApp #### app = QtGui.QApplication([]) # you MUST do this once (initialize things) #################### win = pg.GraphicsWindow( title="Realtime Signals from Driving Kit") # creates a window p1 = win.addPlot(title="Steering Wheel Signal [radians]" ) # creates empty space for the plot in the window curve1 = p1.plot(pen=pg.mkPen( 'r', width=1)) # create an empty "plot" (a curve to plot) p2 = win.addPlot(title="Throttle Signal [Fraction 0-1]") curve2 = p2.plot(pen=pg.mkPen('b', width=1)) p3 = win.addPlot(title="Break Signal [Fraction 0-1]") curve3 = p3.plot(pen=pg.mkPen('g', width=1)) windowWidth = 500 # width of the window displaying the curve Xm1 = linspace( 0, 0, windowWidth) # create array that will contain the relevant time series ptr1 = -windowWidth # set first x position Xm2 = linspace(0, 0, windowWidth) ptr2 = -windowWidth Xm3 = linspace(0, 0, windowWidth) ptr3 = -windowWidth # Serial Defining # ser = serial.Serial("COM7", 57600) t1 = time.time() count = 0 t1 = time.time() while (True): Xm1[:-1] = Xm1[1:] # shift data in the temporal mean 1 sample left Xm2[:-1] = Xm2[1:] Xm3[:-1] = Xm3[1:] pygame.event.pump() jsInputs = [float(js.get_axis(i)) for i in range(numAxes)] steerVal = float(round(round(jsInputs[0], 5) * 7.85398163, 5)) throtVal = float( round( 1 - (((jsInputs[2] - (-1)) * (1.0 - 0)) / (1.0 - (-1.0))) + 0, 4)) breakVal = float( round( 1 - (((jsInputs[3] - (-1)) * (1.0 - 0)) / (1.0 - (-1.0))) + 0, 4)) str_steerVal = 'S' + str(steerVal) str_throtVal = 'T' + str(throtVal) str_breakVal = 'B' + str(breakVal) packet_steer = 'json:' + str_steerVal + "\r\n" packet_throt = 'json:' + str_throtVal + "\r\n" packet_break = 'json:' + str_breakVal + "\r\n" if ser.isOpen(): ser.write(str.encode(packet_steer)) #time.sleep(0.001) ser.write(str.encode(packet_throt)) #time.sleep(0.001) ser.write(str.encode(packet_break)) ##time.sleep(0.001) #ser.write(str.encode(packet)) count = count + 1 else: print("Serial Communication Failed") sys.exit() #t2 = time.time() #dt = t2 - t1 Xm1[-1] = float(steerVal) # vector containing the instantaneous values ptr1 += 1 # update x position for displaying the curve curve1.setData(Xm1) # set the curve with this data curve1.setPos(ptr1, 0) # set x position in the graph to 0 Xm2[-1] = float(throtVal) ptr2 += 1 curve2.setData(Xm2) curve2.setPos(ptr2, 0) Xm3[-1] = float(breakVal) ptr3 += 1 curve3.setData(Xm3) curve3.setPos(ptr3, 0) QtGui.QApplication.processEvents() # you MUST process the plot now keys = [js.get_button(i) for i in range(js.get_numbuttons())] print("Steering : " + str(steerVal) + "[rad] Throttle: " + str(100*throtVal) + \ "% break: " + str( 100*breakVal) + "%") if keys[10] != 0: t2 = time.time() dt = t2 - t1 print(count / dt) sys.exit() pg.QtGui.QApplication.exec_()
def main(): app = QtGui.QApplication([]) fig = ZoomAndPan() fig.show() app.exec_()
def run(*args, **kwargs): app = QtGui.QApplication(sys.argv) app.setStyle(QtGui.QStyleFactory.create('cde')) gui = App() sys.exit(app.exec_())
data_y = self.y_pos[args[0]] val = np.random.random() * 100 return ([data_x, data_y], val) def plot_data(self, *args): #ipdb.set_trace() [x, y] = self.img_loc(args[0][0][0], args[0][0][1]) self.img[x, y] = args[0][1] self.img1.setImage(self.img, lut=self.lut) def imageHoverEvent(self, event): """Show the position, pixel, and value under the mouse cursor. """ if event.isExit(): self.plot1.setTitle("") return pos = event.pos() i, j = pos.y(), pos.x() i = int(np.clip(i, 0, self.img.shape[0] - 1)) j = int(np.clip(j, 0, self.img.shape[1] - 1)) val = self.img[j, i] ##check if the axes are tilted ppos = self.img1.mapToParent(pos) x, y = ppos.x(), ppos.y() self.plot1.setTitle("pos: (%0.1f, %0.1f) value: %g" % (x, y, val)) if __name__ == '__main__': app = QtGui.QApplication([]) win = map_sim() app.exec_()
def main(): app = QtGui.QApplication(sys.argv) app.setApplicationName('TIME Raw Data Visualization Suite') ex = mcegui() sys.exit(app.exec_())