We read every piece of feedback, and take your input very seriously.
Include my email address so I can be contactedHave 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
| @@ -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() |
| @@ -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() |
| @@ -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() |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide commentCan you update this w.r.t. the current methods
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide commentDone in 6e5b923
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.