@@ -273,7 +273,7 @@ class Slider(AxesWidget):
273273 """
274274 def __init__ (self , ax , label , valmin , valmax , valinit = 0.5 , valfmt = '%1.2f' ,
275275 closedmin = True , closedmax = True , slidermin = None ,
276- slidermax = None , dragging = True , ** kwargs ):
276+ slidermax = None , dragging = True , valstep = None , ** kwargs ):
277277 """
278278 Parameters
279279 ----------
@@ -312,6 +312,9 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt='%1.2f',
312312 dragging : bool, optional, default: True
313313 If True the slider can be dragged by the mouse.
314314
315+ valstep : float, optional, default: None
316+ If given, the slider will snap to multiples of `valstep`.
317+
315318 Notes
316319 -----
317320 Additional kwargs are passed on to ``self.poly`` which is the
@@ -334,6 +337,7 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt='%1.2f',
334337 self .drag_active = False
335338 self .valmin = valmin
336339 self .valmax = valmax
340+ self .valstep = valstep
337341 valinit = self ._value_in_bounds (valinit )
338342 if valinit is None :
339343 valinit = valmin
@@ -368,6 +372,10 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt='%1.2f',
368372
369373 def _value_in_bounds (self , val ):
370374 """ Makes sure self.val is with given bounds."""
375+ if self .valstep :
376+ val = np .round ((val - self .valmin )/ self .valstep )* self .valstep
377+ val += self .valmin
378+
371379 if val <= self .valmin :
372380 if not self .closedmin :
373381 return
@@ -410,7 +418,7 @@ def _update(self, event):
410418 event .canvas .release_mouse (self .ax )
411419 return
412420 val = self ._value_in_bounds (event .xdata )
413- if val is not None :
421+ if ( val is not None ) and ( val != self . val ) :
414422 self .set_val (val )
415423
416424 def set_val (self , val ):
0 commit comments