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

Skip to content

Commit c99eea8

Browse files
ianhitimhoffm
andcommitted
Consolidate slider handle styling kwargs
Co-Authored-By: Tim Hoffmann <[email protected]>
1 parent cafc65b commit c99eea8

File tree

1 file changed

+41
-28
lines changed

1 file changed

+41
-28
lines changed

lib/matplotlib/widgets.py

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,7 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt=None,
330330
closedmin=True, closedmax=True, slidermin=None,
331331
slidermax=None, dragging=True, valstep=None,
332332
orientation='horizontal', *, initcolor='r',
333-
track_color='lightgrey', handle_facecolor='white',
334-
handle_edgecolor='.75', handle_size=10, **kwargs):
333+
track_color='lightgrey', handle_style=None, **kwargs):
335334
"""
336335
Parameters
337336
----------
@@ -386,14 +385,16 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt=None,
386385
The color of the background track. The track is accessible for
387386
further styling via the *track* attribute.
388387
389-
handle_facecolor : color, default: 'white'
390-
The facecolor of the circular slider handle.
388+
handle_style : dict
389+
Properties of the slider handle. Supported values are
391390
392-
handle_edgecolor : color, default: '.75'
393-
The edgecolor of the circle slider handle.
394-
395-
handle_size : int, default: 10
396-
The size of the circular slider handle in points.
391+
========= ===== ======= ========================================
392+
Key Value Default Description
393+
========= ===== ======= ========================================
394+
facecolor color 'white' The facecolor of the slider handle.
395+
edgecolor color '.75' The edgecolor of the slider handle.
396+
size int 10 The size of the slider handle in points.
397+
========= ===== ======= ========================================
397398
398399
Notes
399400
-----
@@ -418,6 +419,15 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt=None,
418419
valinit = valmin
419420
self.val = valinit
420421
self.valinit = valinit
422+
423+
marker_props = {}
424+
defaults = {'facecolor':'white', 'edgecolor':'.75', 'size':10}
425+
if handle_style is not None:
426+
for k in ['facecolor', 'edgecolor', 'size']:
427+
marker_props[f'marker{k}'] = handle_style.get(k, defaults[k])
428+
else:
429+
marker_props = {f'marker{k}': v for k, v in defaults.items()}
430+
421431
if orientation == 'vertical':
422432
self.track = Rectangle(
423433
(.25, 0), .5, 1,
@@ -441,9 +451,7 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt=None,
441451
self._handle, = ax.plot(
442452
*handleXY,
443453
"o",
444-
markersize=handle_size,
445-
markeredgecolor=handle_edgecolor,
446-
markerfacecolor=handle_facecolor,
454+
**marker_props,
447455
clip_on=False
448456
)
449457

@@ -598,9 +606,7 @@ def __init__(
598606
valstep=None,
599607
orientation="horizontal",
600608
track_color='lightgrey',
601-
handle_facecolor='white',
602-
handle_edgecolor='.75',
603-
handle_size=10,
609+
handle_style=None,
604610
**kwargs,
605611
):
606612
"""
@@ -645,14 +651,16 @@ def __init__(
645651
The color of the background track. The track is accessible for
646652
further styling via the *track* attribute.
647653
648-
handle_facecolor : color, default: 'white'
649-
The facecolor of the circular slider handle.
654+
handle_style : dict
655+
Properties of the slider handles. Supported values are
650656
651-
handle_edgecolor : color, default: '.75'
652-
The edgecolor of the circular slider handles.
653-
654-
handle_size : int, default: 10
655-
The size of the circular slider handles in points.
657+
========= ===== ======= =========================================
658+
Key Value Default Description
659+
========= ===== ======= =========================================
660+
facecolor color 'white' The facecolor of the slider handles.
661+
edgecolor color '.75' The edgecolor of the slider handles.
662+
size int 10 The size of the slider handles in points.
663+
========= ===== ======= =========================================
656664
657665
Notes
658666
-----
@@ -675,6 +683,15 @@ def __init__(
675683
valinit = self._value_in_bounds(valinit)
676684
self.val = valinit
677685
self.valinit = valinit
686+
687+
marker_props = {}
688+
defaults = {'facecolor':'white', 'edgecolor':'.75', 'size':10}
689+
if handle_style is not None:
690+
for k in ['facecolor', 'edgecolor', 'size']:
691+
marker_props[f'marker{k}'] = handle_style.get(k, defaults[k])
692+
else:
693+
marker_props = {f'marker{k}': v for k, v in defaults.items()}
694+
678695
if orientation == "vertical":
679696
self.track = Rectangle(
680697
(.25, 0), .5, 2,
@@ -699,17 +716,13 @@ def __init__(
699716
ax.plot(
700717
*handleXY_1,
701718
"o",
702-
markersize=handle_size,
703-
markeredgecolor=handle_edgecolor,
704-
markerfacecolor=handle_facecolor,
719+
**marker_props,
705720
clip_on=False
706721
)[0],
707722
ax.plot(
708723
*handleXY_2,
709724
"o",
710-
markersize=handle_size,
711-
markeredgecolor=handle_edgecolor,
712-
markerfacecolor=handle_facecolor,
725+
**marker_props,
713726
clip_on=False
714727
)[0]
715728
]

0 commit comments

Comments
 (0)