Plots disappeared when update image

111 views
Skip to first unread message

Ellito

unread,
Dec 16, 2021, 4:18:58 PM12/16/21
to pyqtgraph
I have multiple items displayed on the pyqtgraph plotWidget, an image and some lines. When I update the image, the line are also removed and not displayed. Could someone advise a way to update the image without removing the lines (I do not want to redraw the line again since it will delay the real-time display)?

Example:
import numpy as np 
import pyqtgraph as pq 
img = np.random.rand(100,100) 
itemShow = pg.ImageItem(img.T) 
imgItem = imWidget.addItem(itemShow) 
penL = pg.mkPen('r') 
lineItem = imWidget.addLine(x=100, pen=penL)

After I updating the imgItem , the line is disappeared at the window.


Patrick

unread,
Dec 16, 2021, 9:57:03 PM12/16/21
to pyqtgraph
Hi,

I'm assuming that you need to ensure the "z-order" of the items is correct (the lines need to be in front of the image). Either insert the image first, then the line plot (and then only update the plot with setData). Or specifically change the z-order with the
setZValue(...) method of the GraphicsItems. This functionality is inherited from the Qt QGraphicsItem https://doc.qt.io/qt-5/qgraphicsitem.html#setZValue which is why it's hard to find...

Patrick
Reply all
Reply to author
Forward
0 new messages