The other day I was working on an Python app that uses PyQt4 for its GUI and pyqtgraph for plotting. I wanted to render some simple geometric shapes on top of an image that is being displayed in a pyqtgraph plot widget Only then did I realize that there is no plot item readily available for such geometric shapes. Though there is an infinite line plot item available in pyqtgraph but that doesn’t meet my requirement. In the documentation however there is an example of how to create custom plot items and it is pretty straight forward. Here is the link to the example.
I have created a few plot item types based on that example and are available at this link. With these custom graphic items one can draw and line, circle or a rectangle as shown below.
plotui = pg.PlotWidget()
I hope this post would be helpful for guys who google for “How to draw a circle/line segment/rectangle in pyqtgraph”.