|
11 | 11 |
|
12 | 12 | from contextlib import ExitStack |
13 | 13 | import copy |
14 | | -from numbers import Integral |
| 14 | +from numbers import Integral, Number |
15 | 15 |
|
16 | 16 | import numpy as np |
17 | 17 |
|
@@ -295,8 +295,9 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt=None, |
295 | 295 | dragging : bool, default: True |
296 | 296 | If True the slider can be dragged by the mouse. |
297 | 297 |
|
298 | | - valstep : float, default: None |
299 | | - If given, the slider will snap to multiples of *valstep*. |
| 298 | + valstep : float or arraylike, default: None |
| 299 | + If a float, the slider will snap to multiples of *valstep*. |
| 300 | + If an array the slider will snap to the values in the array. |
300 | 301 |
|
301 | 302 | orientation : {'horizontal', 'vertical'}, default: 'horizontal' |
302 | 303 | The orientation of the slider. |
@@ -401,9 +402,16 @@ def observers(self): |
401 | 402 |
|
402 | 403 | def _value_in_bounds(self, val): |
403 | 404 | """Makes sure *val* is with given bounds.""" |
404 | | - if self.valstep: |
| 405 | + if isinstance(self.valstep, Number): |
405 | 406 | val = (self.valmin |
406 | 407 | + round((val - self.valmin) / self.valstep) * self.valstep) |
| 408 | + elif self.valstep is not None: |
| 409 | + valstep = np.asanyarray(self.valstep) |
| 410 | + if valstep.ndim != 1: |
| 411 | + raise ValueError( |
| 412 | + f"valstep must have 1 dimension but has {valstep.ndim}" |
| 413 | + ) |
| 414 | + val = valstep[np.argmin(np.abs(valstep - val))] |
407 | 415 |
|
408 | 416 | if val <= self.valmin: |
409 | 417 | if not self.closedmin: |
|
0 commit comments