I would like to understand some parts of the library "PyQtGraph", especially when it comes to 2D plot.
In the source code, the two python files are the following : PlotDataItem.py
and PlotCurveItem.py
(they are located in pyqtgraph/graphicsItems/
). But in these two files, I don't see any function to plot. I mean we have only methods to save x and y data (self.yData
and self.xData
). Where are the methods to, stricly speaking, plot the data? (The equivalent to draw()
in matplotlib.)
EDIT : Thank you for your answer. I am reading the source code and yes I found that there is something in ViewBox.addItem. In fact,I tried to remove some parts of the code in order to see if the curve disseapeared. The lines : scene.addItem(item) and item.setParentItem(self.childGroup) seems important. Anyway, you mean that I have to focus on QGraphicsScene and QGraphicsView ? Would you confirm me that PlotDataItem is just a file in which x and y datas are "saved" and there is no "plot" ?
The short answer is that PyQtGraph delegates the drawing to the Qt's Graphics View Framework. PyQtGraph will create a QGraphicsScene
and adds QGraphicsItems
to that scene. If you connect a QGraphicsView
object to that scene, Qt will render the scene with the transformations (zoom, rotation, etc) of that view for you.
So PlotCurveItem
and PlotDataItem
are descendants of QGraphicsItem
. You can find out which scene they belong to by calling their scene()
method. It took me a bit effort to find where PyQtGraph adds the item to the scene. This is done in ViewBox.addItem
, which is called by PlotItem.addItem
, which in turn is called by PlotWidget.addItem
.
The section on Organization of Plotting Classes is a must read if you want to understand PyQtGraph. Still, the PyQtGraph class hierarchy can be confusing sometimes because of multiple inheritance and naming inconsistencies (the terms item and widget are overloaded, and a consistent naming convention would probably result in long and unwieldy names). I have made a UML diagram in the past to get a better overview (see below). The blue classes are defined by PyQtGraph, the black classes are Qt classes. It is not complete, not all PyQtGraph classes are included.