Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Picking for scatter item #4166

Closed
vallsv opened this issue Aug 27, 2024 · 2 comments
Closed

Picking for scatter item #4166

vallsv opened this issue Aug 27, 2024 · 2 comments

Comments

@vallsv
Copy link
Contributor

vallsv commented Aug 27, 2024

Sounds like the picking for scatters is not implemented for scatter, with raster rendering.

So for now in Flint i use a fallback, which is probably always used.

from silx.gui.plot.items.scatter import Scatter

def isScatter(item):
    return isinstance(item, Scatter)

results = list(plot.pickItems(x, y, isScatter))
for result in results:
    indices = result.getIndices(copy=False)
    return indices

if len(results) == 0:
    selectedScatter = plot.getActiveScatter()
    # Pick on the active curve with a higher tolerance
    if selectedScatter is not None:
        index = __closest(selectedScatter, x, y)
        return index

def __closest(scatter, x, y) -> int | None:
    """Returns the closest index from a scatter item"""
    xx = scatter.getXData()
    yy = scatter.getYData()
    if xx is None or len(xx) == 0:
        return None
    dist = (xx - x) ** 2 + (yy - y) ** 2
    index = numpy.nanargmin(dist)
    return index
@t20100 t20100 added this to the Next release milestone Aug 29, 2024
@t20100
Copy link
Member

t20100 commented Aug 29, 2024

From a quick test, I don't seen any issue with any of the scatter visualisation mode:

from silx import sx
w = sx.scatter([0, 0, 0, 1, 1, 1, 2, 2, 2], [0, 1, 2, 0, 1, 2, 0, 1, 2], [0, 1, 2, 3, 4, 5, 6, 7, 8])

When picking at a position where there is a Scatter, you get it:

In [26]: list(w.getPlotWidget().pickItems(279, 232))[0].getIndices()
Out[26]: array([1])

Maybe you are after always getting the closest point as your code suggests? That is not provided by the picking API.

@vallsv
Copy link
Contributor Author

vallsv commented Sep 2, 2024

Yes, sounds good. I probably have a wrong transformation somehow.

The code i have copy-pasted use the picking with data coords, so i have to double check on my side.

@vallsv vallsv closed this as completed Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants