-
Notifications
You must be signed in to change notification settings - Fork 63
Allow use of add_*_selector methods in ScatterGraphic
#883
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
Open
lkeegan
wants to merge
18
commits into
fastplotlib:main
Choose a base branch
from
lkeegan:scatter_graphic_add_linear_selector
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+422
−196
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
acab9d0
Allow use of `add_*_selector` methods in `ScatterGraphic`
lkeegan 5ae771e
Update linear/rectangle selectors to work with ScatterGraphics, add e…
lkeegan c5ec080
refactor bounds_init logic to make intent clearer, add comment, remov…
lkeegan 75b7d73
restore y-padding on rectangle selector limits, refactored to also wo…
lkeegan c28163f
Merge branch 'main' into scatter_graphic_add_linear_selector
lkeegan e2d6b9f
Add `add_polygon_selector` method to `ScatterGraphic` and create an e…
lkeegan 8776b29
allow selection to extend by 25% padding in all directions
lkeegan 7898ad2
enable ground truth screenshots for scatter selector examples
lkeegan 82870b9
set initial polygon selection in example and reset _move_info after s…
lkeegan 9054ae0
Merge branch 'main' into scatter_graphic_add_linear_selector
lkeegan 2b607b5
Update fastplotlib/graphics/selectors/_polygon.py
lkeegan 5313a05
Update fastplotlib/graphics/selectors/_rectangle.py
lkeegan 481138b
Update fastplotlib/graphics/selectors/_polygon.py
lkeegan 41c3a02
run black on examples/selection_tools/linear_region_scatter.py
lkeegan 4db8d34
Merge branch 'main' into scatter_graphic_add_linear_selector
lkeegan 6e5b923
update add_*_selector to match main branch (keeping previous changes …
lkeegan 4598ae0
fix typos
lkeegan b0720b4
Add sizes to linear region scatter example
lkeegan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| """ | ||
| LinearRegionSelectors with ScatterGraphic | ||
| ========================================= | ||
|
|
||
| Example showing how to use a `LinearRegionSelector` with a scatter plot. We demonstrate two use cases, a horizontal | ||
| LinearRegionSelector which selects along the x-axis and a vertical selector which moves along the y-axis. | ||
| """ | ||
|
|
||
| # test_example = true | ||
| # sphinx_gallery_pygfx_docs = 'screenshot' | ||
|
|
||
| import fastplotlib as fpl | ||
| import numpy as np | ||
|
|
||
| # names for out subplots | ||
| names = [["scatter x", "scatter y"], ["zoomed x region", "zoomed y region"]] | ||
|
|
||
| # 2 rows, 2 columns | ||
| figure = fpl.Figure( | ||
| (2, 2), | ||
| size=(700, 560), | ||
| names=names, | ||
| ) | ||
|
|
||
| scatter_x_data = (100 * np.random.random_sample(size=(500, 2))).astype(np.float32) | ||
| scatter_y_data = (100 * np.random.random_sample(size=(500, 2))).astype(np.float32) | ||
|
|
||
| # plot scatter data | ||
| scatter_x = figure[0, 0].add_scatter(scatter_x_data, sizes=4) | ||
| scatter_y = figure[0, 1].add_scatter(scatter_y_data, sizes=4) | ||
|
|
||
| # add linear selectors | ||
| selector_x = scatter_x.add_linear_region_selector((0, 100)) # default axis is "x" | ||
| selector_y = scatter_y.add_linear_region_selector(axis="y") | ||
|
|
||
|
|
||
| @selector_x.add_event_handler("selection") | ||
| def set_zoom_x(ev): | ||
| """sets zoomed x selector data""" | ||
| selected_data = ev.get_selected_data() | ||
| figure[1, 0].clear() | ||
| figure[1, 0].add_scatter(selected_data, sizes=10) | ||
| figure[1, 0].auto_scale() | ||
|
|
||
|
|
||
| @selector_y.add_event_handler("selection") | ||
| def set_zoom_y(ev): | ||
| """sets zoomed y selector data""" | ||
| selected_data = ev.get_selected_data() | ||
| figure[1, 1].clear() | ||
| figure[1, 1].add_scatter(selected_data, sizes=10) | ||
| figure[1, 1].auto_scale() | ||
|
|
||
|
|
||
| # set initial selection | ||
| selector_x.selection = (30, 60) | ||
| selector_y.selection = (30, 60) | ||
|
|
||
| figure.show(maintain_aspect=False) | ||
|
|
||
| # NOTE: fpl.loop.run() should not be used for interactive sessions | ||
| # See the "JupyterLab and IPython" section in the user guide | ||
| if __name__ == "__main__": | ||
| print(__doc__) | ||
| fpl.loop.run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| """ | ||
| Polygon Selectors with ScatterGraphic | ||
| ===================================== | ||
|
|
||
| Example showing how to use a `PolygonSelector` with a scatter plot. | ||
| """ | ||
|
|
||
| # test_example = true | ||
| # sphinx_gallery_pygfx_docs = 'screenshot' | ||
|
|
||
| import numpy as np | ||
| import fastplotlib as fpl | ||
|
|
||
| # create a figure | ||
| figure = fpl.Figure( | ||
| (1, 2), | ||
| size=(700, 560), | ||
| names=["scatter", "zoomed selection"], | ||
| ) | ||
|
|
||
| xys = (100 * np.random.random_sample(size=(2000, 2))).astype(np.float32) | ||
|
|
||
| # add image | ||
| scatter = figure[0, 0].add_scatter(xys, cmap="jet", sizes=4) | ||
|
|
||
| # add polygon selector to scatter graphic | ||
| polygon_selector = scatter.add_polygon_selector() | ||
|
|
||
| # add event handler to highlight selected indices and display selected data in zoomed plot | ||
| @polygon_selector.add_event_handler("selection") | ||
| def color_indices(ev): | ||
| figure[0, 1].clear() | ||
| scatter.cmap = "jet" | ||
| scatter.sizes = 4 | ||
| ixs = ev.get_selected_indices() | ||
| if ixs.size == 0: | ||
| return | ||
| scatter.colors[ixs] = 'w' | ||
| scatter.sizes[ixs] = 8 | ||
| figure[0, 1].add_scatter(ev.get_selected_data(), sizes=16) | ||
| figure[0, 1].auto_scale() | ||
|
|
||
| # set initial selection | ||
| polygon_selector.selection = [(50.0, 20.0,0.0), (80.0,80.0,0.0), (20.0, 50.0,0.0), (50.0, 50.0, 0.0), (50.0, 20.0,0.0)] | ||
|
|
||
| figure.show() | ||
|
|
||
| # NOTE: fpl.loop.run() should not be used for interactive sessions | ||
| # See the "JupyterLab and IPython" section in the user guide | ||
| if __name__ == "__main__": | ||
| print(__doc__) | ||
| fpl.loop.run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| """ | ||
| Rectangle Selectors with ScatterGraphic | ||
| ======================================= | ||
|
|
||
| Example showing how to use a `RectangleSelector` with a scatter plot. | ||
| """ | ||
|
|
||
| # test_example = true | ||
| # sphinx_gallery_pygfx_docs = 'screenshot' | ||
|
|
||
| import numpy as np | ||
| import fastplotlib as fpl | ||
|
|
||
| # create a figure | ||
| figure = fpl.Figure( | ||
| size=(700, 560) | ||
| ) | ||
|
|
||
| xys = (100 * np.random.random_sample(size=(200, 2))).astype(np.float32) | ||
|
|
||
| # add image | ||
| scatter = figure[0, 0].add_scatter(xys, cmap="jet", sizes=4) | ||
|
|
||
| # add rectangle selector to image graphic | ||
| rectangle_selector = scatter.add_rectangle_selector() | ||
|
|
||
| # add event handler to highlight selected indices | ||
| @rectangle_selector.add_event_handler("selection") | ||
| def color_indices(ev): | ||
| scatter.cmap = "jet" | ||
| scatter.sizes = 4 | ||
| ixs = ev.get_selected_indices() | ||
| if ixs.size == 0: | ||
| return | ||
| scatter.colors[ixs] = 'w' | ||
| scatter.sizes[ixs] = 8 | ||
|
|
||
|
|
||
| # manually move selector to make a nice gallery image :D | ||
| rectangle_selector.selection = (20, 40, 40, 60) | ||
|
|
||
|
|
||
| figure.show() | ||
|
|
||
| # NOTE: fpl.loop.run() should not be used for interactive sessions | ||
| # See the "JupyterLab and IPython" section in the user guide | ||
| if __name__ == "__main__": | ||
| print(__doc__) | ||
| fpl.loop.run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update this w.r.t. the current methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 6e5b923