Skip to content

The rangeslider seems to be broken #195

@kmdalton

Description

@kmdalton

Bug report

I tried creating a rangeslider under ipyplot.imshow by passing a keyword argument ("r", 1., 99., 99). When I actuate the slider, I get a complicated traceback and nothing happens. Here's a simple example to reproduce. I was trying to create a percentile based contrast slider.

from matplotlib import pyplot as plt
from mpl_interactions import ipyplot as iplt
import numpy as np


img = plt.imread("https://matplotlib.org/3.3.1/_images/stinkbug.png")


fig,ax = plt.subplots()

def f(prange):
    pmin,pmax = prange
    vmin = np.percentile(img, pmin)
    vmax = np.percentile(img, pmax)
    truncated = img.copy()
    truncated = np.maximum(vmin, truncated)
    truncated = np.minimum(vmax, truncated)
    return truncated

controls = iplt.imshow(f, prange=("r", 1., 99., 99))
plt.show()

I get a traceback like this when I move the sliders:

Traceback (most recent call last):
  File "anaconda/envs/whatever/lib/python3.8/site-packages/matplotlib/cbook/__init__.py", line 224, in process
    func(*args, **kwargs)
  File "anaconda/envs/whatever/lib/python3.8/site-packages/mpl_interactions/helpers.py", line 394, in changeify
    update({"new": val})
  File "anaconda/envs/whatever/lib/python3.8/site-packages/mpl_interactions/controller.py", line 182, in slider_updated
    self._slider_updated(change, key, values)
  File "anaconda/envs/whatever/lib/python3.8/site-packages/mpl_interactions/controller.py", line 156, in _slider_updated
    self.params[key] = values[int(change["new"])]
TypeError: only size-1 arrays can be converted to Python scalars

Version Info
I saw this bug on 0.17.0 and 0.17.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions