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

Skip to content

Commit 70ff4cd

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

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-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: 9 additions & 3 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
----------
@@ -302,6 +302,10 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt=None,
302302
orientation : {'horizontal', 'vertical'}, default: 'horizontal'
303303
The orientation of the slider.
304304
305+
initcolor : color or None, default: 'r'
306+
The color of the line drawn at the *valinit* position. If None
307+
then no line marking the inital position will be drawn.
308+
305309
Notes
306310
-----
307311
Additional kwargs are passed on to ``self.poly`` which is the
@@ -353,10 +357,12 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt=None,
353357
self.valinit = valinit
354358
if orientation == 'vertical':
355359
self.poly = ax.axhspan(valmin, valinit, 0, 1, **kwargs)
356-
self.hline = ax.axhline(valinit, 0, 1, color='r', lw=1)
360+
if initcolor is not None:
361+
self.hline = ax.axhline(valinit, 0, 1, color=initcolor, lw=1)
357362
else:
358363
self.poly = ax.axvspan(valmin, valinit, 0, 1, **kwargs)
359-
self.vline = ax.axvline(valinit, 0, 1, color='r', lw=1)
364+
if initcolor is not None:
365+
self.vline = ax.axvline(valinit, 0, 1, color=initcolor, lw=1)
360366

361367
if orientation == 'vertical':
362368
ax.set_ylim((valmin, valmax))

0 commit comments

Comments
 (0)