I’m at present making an attempt to create a buying and selling utility by way of pyqt5 and pyqtgraph.
To show the chart I exploit the instance code given within the pyqtgraph examples.
import pyqtgraph as pg from pyqtgraph import QtCore, QtGui ## Create a subclass of GraphicsObject. ## The one required strategies are paint() and boundingRect() ## (see QGraphicsItem documentation) class CandlestickItem(pg.GraphicsObject): def __init__(self, information): pg.GraphicsObject.__init__(self) self.information = information ## information will need to have fields: time, open, shut, min, max self.generatePicture() def generatePicture(self): ## pre-computing a QPicture object permits paint() to run rather more rapidly, ## somewhat than re-drawing the shapes each time. self.image = QtGui.QPicture() p = QtGui.QPainter(self.image) p.setPen(pg.mkPen('w')) w = (self.information - self.information) / 3. for (t, open, shut, min, max) in self.information: p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max)) if open > shut: p.setBrush(pg.mkBrush('r')) else: p.setBrush(pg.mkBrush('g')) p.drawRect(QtCore.QRectF(t-w, open, w*2, close-open)) p.finish() def paint(self, p, *args): p.drawPicture(0, 0, self.image) def boundingRect(self): ## boundingRect _must_ point out the whole space that will likely be drawn on ## or else we'll get artifacts and presumably crashing. ## (on this case, QPicture does all of the work of computing the bouning rect for us) return QtCore.QRectF(self.image.boundingRect()) information = [ ## fields are (time, open, close, min, max). (1., 10, 13, 5, 15), (2., 13, 17, 9, 20), (3., 17, 14, 11, 23), (4., 14, 15, 5, 19), (5., 15, 9, 8, 22), (6., 9, 15, 8, 16), ] merchandise = CandlestickItem(information) plt = pg.plot() plt.addItem(merchandise) plt.setWindowTitle('pyqtgraph instance: customGraphicsItem') ## Begin Qt occasion loop except operating in interactive mode or utilizing pyside. if __name__ == '__main__': import sys if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): QtGui.QApplication.occasion().exec_()
I want to create indicators to show on the graph.
I’ve tried many issues that did not work to keep away from repeating code and the one method that works nicely is to easily put the code I wrote above again into every indicator with the adjustments I would like and show them on high of the graph.
I want to know in case you have an concept easy methods to do it in a different way.
If you would like extra data, let me know.