def getPath(self): if self.path is None: if self.data is None or len(self.data) < 2: self.path = [QtGui.QPainterPath(), QtGui.QPainterPath()] else: redBars = QtGui.QPainterPath() greenBars = QtGui.QPainterPath() self.step = self.data[1][0] - self.data[0][0] w = self.step / 3.0 for data in self.data: if not np.isnan(data).any(): t, o, h, l, c = data if o > c: redBars.moveTo(QtCore.QPointF(t, l)) redBars.lineTo(QtCore.QPointF(t, h)) redBars.addRect( QtCore.QRectF(t - w, o, w * 2, c - o)) else: greenBars.moveTo(QtCore.QPointF(t, l)) greenBars.lineTo(QtCore.QPointF(t, h)) greenBars.addRect( QtCore.QRectF(t - w, o, w * 2, c - o)) self.path = [redBars, greenBars] return self.path
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. x = self.xdat[:5] y = self.ydat[:5] self.path = pg.arrayToQPath(self.xdat, self.ydat, self.connect) # self.path = pg.arrayToQPath(np.array([0, 1, 1, 0, 3, 1]), np.array([0, 0, 1, 1, 3, 1])) p2 = QtGui.QPainterPath(self.path) p.fillPath(p2, pg.mkBrush((100, 100, 100))) # for (t, open, close, min, max) in self.data: # p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max)) # self.path = pg.arrayToQPath(np.array([0, 1, 2, 1]), np.array([0, 0, 1, 1])) # # self.path = self.generatePath([0, 1, 2, 1], [0, 0, 1, 1]) # p2 = QtGui.QPainterPath(self.path) # p.fillPath(p2, pg.mkBrush((100, 100, 100))) # if open > close: # p.setBrush(pg.mkBrush('r')) # else: # p.setBrush(pg.mkBrush('g')) # p.drawRect(QtCore.QRectF(t - w, open, w * 2, close - open)) # p.drawPolygon(QtCore.) # p.drawLine(QtCore.QPointF(*pts[i][0]), QtCore.QPointF(*pts[i][1])) p.end()
def shape(self): """ Function required by one or another superclass. Define the shape of this cutline. """ p = QtGui.QPainterPath() h1 = self.endpoints[0] h2 = self.endpoints[1] dh = h2 - h1 if dh.length() == 0: return p pxv = self.pixelVectors(dh)[1] if pxv is None: return p pxv *= 5 p.moveTo(h1 + pxv) p.lineTo(h2 + pxv) p.lineTo(h2 - pxv) p.lineTo(h1 - pxv) p.lineTo(h1 + pxv) return p
def getPath(self): if self.path is None: if self.data is None or len(self.data) < 2: self.path = [QtGui.QPainterPath(), QtGui.QPainterPath()] else: redBars = QtGui.QPainterPath() greenBars = QtGui.QPainterPath() step = self.data[1][0] - self.data[0][0] w = step / 3.0 for t, buy, sell in self.data: if buy + sell != 0: redBars.addRect(QtCore.QRectF(t - w, 0, w * 2, sell)) greenBars.addRect(QtCore.QRectF(t - w, sell, w * 2, buy)) self.path = [redBars, greenBars] return self.path
def generatePicture(self): """ Pre-compute a QPicture object to allow paint() to run much more quickly, :return: """ self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen('w')) for i in range(len(self.xdata)): path = pg.arrayToQPath(self.xdata[i], self.ydata[i]) p2 = QtGui.QPainterPath(path) p.fillPath(p2, pg.mkBrush((100, 100, 10 + i * 1))) p.end()
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')) for i in range(int(len(self.xdat) / 5)): print(self.xdat[i*5:(i+1) * 5], self.ydat[i*5:(i+1) * 5]) self.path = pg.arrayToQPath(self.xdat[i * 5:(i+1) * 5], self.ydat[i * 5:(i+1) * 5]) # self.path = pg.arrayToQPath(np.array([0, 1, 1, 0, 3, 1]), np.array([0, 0, 1, 1, 3, 1])) p2 = QtGui.QPainterPath(self.path) p.fillPath(p2, pg.mkBrush((100, 100, 10 + i * 10))) p.end()
def generatePicture(self): """ Pre-compute a QPicture object to allow paint() to run much more quickly, :return: """ self.picture = QtGui.QPicture() p = QtGui.QPainter(self.picture) p.setPen(pg.mkPen(self.pen_col)) for i in range(len(self.xdata)): path = pg.arrayToQPath(self.xdata[i], self.ydata[i]) p2 = QtGui.QPainterPath(path) if self.brushes is None: brush = pg.mkBrush((100, 100, 10 + i * 1)) else: brush = self.brushes[i] p.fillPath(p2, brush) p.drawPath(p2) p.end()