Skip to content

A more reusable Slicer - #553

Merged
nvaytet merged 16 commits into
mainfrom
more-reusable-slicer
Apr 17, 2026
Merged

nvaytet merged 16 commits into
mainfrom
more-reusable-slicer

Conversation

@nvaytet

@nvaytet nvaytet commented Apr 14, 2026 •

Copy link
Copy Markdown
Member

We split the Slicer class into two parts:

  • one that creates the slider widgets and slices the data (can access the result in the nodes stored in the output attribute
  • one that creates the above + a figure

The first one can then be used with other visualizations (e.g. the instrument view), while the second can be used by similar slicer views like the Superplot.

A quick example of something we can now do with this: update a html display from the slider

import plopp as pp
from plopp.plotting.slicer import Slicer
import ipywidgets as ipw

da = pp.data.data2d()

s = Slicer(da)

# Make a html widget
html = ipw.HTML()

# Function to display data array as html
def f(da):
    html.value = da._repr_html_()

pp.Node(f, da=s.output[0])

ipw.VBox([s.slider, html])
Screenshot_20260414_194358

This should hopefully be quite useful for integrating as part of custom GUI interfaces.

@nvaytet
nvaytet marked this pull request as draft April 14, 2026 08:52
@nvaytet
nvaytet marked this pull request as ready for review April 14, 2026 13:06
Comment on lines -102 to -109
nodes = input_to_nodes(
obj,
processor=partial(preprocess, ignore_size=True, coords=coords),
)

dims = nodes[0]().dims
if keep is None:
keep = dims[-(2 if len(dims) > 2 else 1) :]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we still keep these checks? Slicer can still accept obj: PlottableMulti as input?

@nvaytet
nvaytet requested a review from MridulS April 17, 2026 09:37
@nvaytet

nvaytet commented Apr 17, 2026

Copy link
Copy Markdown
Member Author

I ended up using the new functionality in one of the gallery notebooks.
It shows well how it improves usability:

Code before:

slider = pw.SliceWidget(da, dims=['time'])
slider_node = pp.widget_node(slider)

slice_node = pw.slice_dims(data_array=da, slices=slider_node)

fig = pp.scatter3dfigure(slice_node, size=0.3, cbar=True)

pp.widgets.Box([fig, slider])

After:

from plopp.plotting.slicer import Slicer

sl = Slicer(da, keep='pixel')

fig = pp.scatter3dfigure(sl.output, size=0.3, cbar=True)

fig.bottom_bar.add(sl.slider)

fig

@nvaytet
nvaytet merged commit 016fff0 into main Apr 17, 2026
6 checks passed
@nvaytet
nvaytet deleted the more-reusable-slicer branch April 17, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants