ipywidgets icon indicating copy to clipboard operation
ipywidgets copied to clipboard

Custom slider labels via function of value

Open mattragoza opened this issue 3 years ago • 1 comments

Hello, thanks for this great package.

I have one feature request that would extremely useful for my use case. Similar to how matplotlib has a conceptual distinction between the axes ticks and axes tick labels, it would be great if there were a way to distinguish the values of a widget (for example, a slider) from the label that is displayed next to the slider.

My use case is that I have some data stored in an N-dimensional array and I use sliders to control what slice of the array is being viewed by matplotlib.pyplot.implot. However the array dimensions have physical meaning (spatial coordinates, etc.) that I would like to use to label the slider position instead of showing the raw array index.

The API could either by a function that is provided as an additional argument to widget which is applied to the value before being displayed, or an iterable of enumerated labels (similar to the ticklabels in matplotlib).

Is this feasible to implement?

mattragoza avatar Jul 18 '22 15:07 mattragoza

Hi @mattragoza this achievable with either a selectionslider (https://github.com/jupyter-widgets/ipywidgets/issues/2902) or with a an IntSlider and a Label. The latter is what I do in mpl-interactions which you can see here: https://github.com/ianhi/mpl-interactions/blob/6d71611501771fce78b9306ff2e2c1fec4c68cba/mpl_interactions/helpers.py#L383-L390

My use case is that I have some data stored in an N-dimensional array and I use sliders to control what slice of the array is being viewed by matplotlib.pyplot.implot. However the array dimensions have physical meaning (spatial coordinates, etc.) that I would like to use to label the slider position instead of showing the raw array index.

You're looking for hyperslicer! Which solves exactly this problem (and even integrates with xarray if you use that). The particular section of that docs page you want is this one

ianhi avatar Jul 18 '22 16:07 ianhi