Select ScatterPlotItem points using ROI

779 views
Skip to first unread message

Jorge Gil

unread,
Mar 30, 2014, 1:27:19 PM3/30/14
to pyqt...@googlegroups.com
Hi,

Is it possible to use a ROI to select ScatterplotItemPoints?

The PyQtGraph examples only show ROI interacting with Raster images, not point data.

Thank you,
Jorge

Luke Campagnola

unread,
Mar 30, 2014, 5:00:34 PM3/30/14
to pyqt...@googlegroups.com
On Sun, Mar 30, 2014 at 1:27 PM, Jorge Gil <gil....@gmail.com> wrote:
Is it possible to use a ROI to select ScatterplotItemPoints?

The PyQtGraph examples only show ROI interacting with Raster images, not point data.

In the most general case (for arbitrarily-shaped ROIs), I think you just have to ask whether each point is found inside the ROI shape
For example:

# get ROI shape in coordinate system of the scatter plot
roiShape = roi.mapToItem(scatterPlot, roi.shape())
# Get list of all points inside shape
selected = [pt for pt in scatterPlotPoints if roiShape.contains(pt)]

For simple ROI shapes, you might be able to do something more efficient, like find all points within certain x/y ranges for a rectangular ROI.
Let me know if you need more help with this.


Luke

Jorge Gil

unread,
Apr 1, 2014, 10:52:14 AM4/1/14
to pyqt...@googlegroups.com
Dear Luke,

Thanks for the reply.
From it I understand that there are no built-in functions for point in ROI shape check.

I'll have to decide on the best way to do it considering that I might have many thousands of points and it will get too slow. Might even stick with the rectangle for performance and simplicity.

Once I get back to this problem, and if I need more help, I'll let you know.

Thanks,
Jorge
--
You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyqtgraph/KCOSX_D_ctA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/CACZXET8p56eChL6QbQ64NR-8YGT1DOGPbh8dZ%3DdMh_EeYKKjNQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Luke Campagnola

unread,
Apr 1, 2014, 11:08:49 AM4/1/14
to pyqt...@googlegroups.com
On Tue, Apr 1, 2014 at 10:52 AM, Jorge Gil <gil....@gmail.com> wrote:
From it I understand that there are no built-in functions for point in ROI shape check.

In the example I provided, QGraphicsItem.shape() returns a QPainterPath, which has a .contains() method for testing whether a point is inside the path. See:


I'll have to decide on the best way to do it considering that I might have many thousands of points and it will get too slow. 
Might even stick with the rectangle for performance and simplicity.

Try it first, then optimize. A compromise might be to first select all points within the bounding rectangle of the shape (see QPainterPath.boundingRect) because this can be done quickly, and then do the more expensive QPainterPath.contains() with that smaller subset of points. 


Jorge Gil

unread,
Apr 1, 2014, 11:15:31 AM4/1/14
to pyqt...@googlegroups.com
Dear Luke,

Thanks for the examples and links to the documentation, I hadn't realised you were using QGraphicsItem.shape() and contains()! I'm a Qt beginner, as well as pyqtgraph...

I'll follow your suggestions, it sounds very feasible this way.

Best,
Jorge
--
You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyqtgraph/KCOSX_D_ctA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyqtgraph+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages