Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0baa16b

Browse files
committed
allow not drawing the line marking initial slider position
1 parent ee8f9d0 commit 0baa16b

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

examples/widgets/slider_snap_demo.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""
2-
==========================
3-
Slider Value Snapping Demo
4-
==========================
2+
===================================
3+
Snapping Sliders to Discrete Values
4+
===================================
55
6-
You can snap slider values to a discrete values using the ``valstep`` argument.
6+
You can snap slider values to discrete values using the ``valstep`` argument.
77
88
In this example the Freq slider is constrained to be multiples of pi, and the
99
Amp slider uses an array as the ``valstep`` argument to more densely sample
@@ -39,10 +39,8 @@
3939
sfreq = Slider(
4040
ax_freq, "Freq", 0, 10*np.pi,
4141
valinit=2*np.pi, valstep=np.pi,
42-
initcolor=None
42+
initcolor='none' # Remove the line marking the valinit position.
4343
)
44-
# initcolor is set to None to remove the line marking the valinit position
45-
4644

4745
def update(val):
4846
amp = samp.val

lib/matplotlib/widgets.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class Slider(AxesWidget):
255255
def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt=None,
256256
closedmin=True, closedmax=True, slidermin=None,
257257
slidermax=None, dragging=True, valstep=None,
258-
orientation='horizontal', **kwargs):
258+
orientation='horizontal', *, initcolor='r', **kwargs):
259259
"""
260260
Parameters
261261
----------
@@ -295,13 +295,17 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt=None,
295295
dragging : bool, default: True
296296
If True the slider can be dragged by the mouse.
297297
298-
valstep : float or arraylike, default: None
298+
valstep : float or array-like, default: None
299299
If a float, the slider will snap to multiples of *valstep*.
300300
If an array the slider will snap to the values in the array.
301301
302302
orientation : {'horizontal', 'vertical'}, default: 'horizontal'
303303
The orientation of the slider.
304304
305+
initcolor : color, default: 'r'
306+
The color of the line at the *valinit* position. Set to ``'none'``
307+
for no line.
308+
305309
Notes
306310
-----
307311
Additional kwargs are passed on to ``self.poly`` which is the
@@ -338,10 +342,10 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt=None,
338342
self.valinit = valinit
339343
if orientation == 'vertical':
340344
self.poly = ax.axhspan(valmin, valinit, 0, 1, **kwargs)
341-
self.hline = ax.axhline(valinit, 0, 1, color='r', lw=1)
345+
self.hline = ax.axhline(valinit, 0, 1, color=initcolor, lw=1)
342346
else:
343347
self.poly = ax.axvspan(valmin, valinit, 0, 1, **kwargs)
344-
self.vline = ax.axvline(valinit, 0, 1, color='r', lw=1)
348+
self.vline = ax.axvline(valinit, 0, 1, color=initcolor, lw=1)
345349

346350
if orientation == 'vertical':
347351
ax.set_ylim((valmin, valmax))

0 commit comments

Comments
 (0)