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

Skip to content

Commit 24fdcd4

Browse files
committed
allow not drawing the line marking initial slider position
1 parent 822c3c7 commit 24fdcd4

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

examples/widgets/slider_snap_demo.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@
3131
allowed_amplitudes = np.concatenate([np.linspace(.1, 5, 100), [7, 8, 9, 10]])
3232

3333
# create the sliders
34-
samp = Slider(axamp, 'Amp', 0.1, 10.0, valinit=a0, valstep=allowed_amplitudes)
35-
sfreq = Slider(axfreq, 'Freq', 0, 10*np.pi, valinit=f0, valstep=np.pi)
34+
samp = Slider(axamp, "Amp", 0.1, 10.0, valinit=a0, valstep=allowed_amplitudes)
35+
36+
# set initcolor to None to remove the line marking the valinit position
37+
sfreq = Slider(
38+
axfreq, "Freq", 0, 10 * np.pi, valinit=f0, valstep=np.pi, initcolor=None
39+
)
3640

3741

3842
def update(val):

lib/matplotlib/widgets.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ 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', valsnap=None,
259+
**kwargs):
259260
"""
260261
Parameters
261262
----------
@@ -302,6 +303,10 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt=None,
302303
orientation : {'horizontal', 'vertical'}, default: 'horizontal'
303304
The orientation of the slider.
304305
306+
initcolor : color or None, default: 'r'
307+
The color of the line drawn at the *valinit* position. If None
308+
then no line marking the inital position will be drawn.
309+
305310
Notes
306311
-----
307312
Additional kwargs are passed on to ``self.poly`` which is the
@@ -353,10 +358,12 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt=None,
353358
self.valinit = valinit
354359
if orientation == 'vertical':
355360
self.poly = ax.axhspan(valmin, valinit, 0, 1, **kwargs)
356-
self.hline = ax.axhline(valinit, 0, 1, color='r', lw=1)
361+
if initcolor is not None:
362+
self.hline = ax.axhline(valinit, 0, 1, color=initcolor, lw=1)
357363
else:
358364
self.poly = ax.axvspan(valmin, valinit, 0, 1, **kwargs)
359-
self.vline = ax.axvline(valinit, 0, 1, color='r', lw=1)
365+
if initcolor is not None:
366+
self.vline = ax.axvline(valinit, 0, 1, color=initcolor, lw=1)
360367

361368
if orientation == 'vertical':
362369
ax.set_ylim((valmin, valmax))

0 commit comments

Comments
 (0)