Skip to content

Create a RangeSlider widget #18563

@ianhi

Description

@ianhi

Problem

Currently, if you want to use widgets to set two related values (e.g. vmin and vmax for thresholding an image) you need to create two sliders. This makes it difficult to maintain the same experience between ipywidgets and matplotlib widgets. In particular I would like to be able to use this thresholding setup with both ipywidgets and matplotlib widgets

%matplotlib ipympl
import matplotlib.pyplot as plt
import ipywidgets as widgets
img = plt.imread("https://matplotlib.org/3.3.1/_images/stinkbug.png")

fig, ax = plt.subplots()
im = ax.imshow(img)
slider = widgets.FloatRangeSlider(value=(0.,1.), min=0, max=1., step=.001)
def update(change):
    im.norm.vmin = slider.value[0]
    im.norm.vmax = slider.value[1]
    fig.canvas.draw()
slider.observe(update, names='value')
display(slider)

thesholding-ipy

Proposed Solution

Create a RangeSlider class in widgets.py that give analogous behavior to the ipywidgets version: https://ipywidgets.readthedocs.io/en/stable/examples/Widget%20List.html#FloatRangeSlider

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions