@@ -269,6 +269,7 @@ def __init__(self, ax, orientation, closedmin, closedmax,
269
269
270
270
ax .set_axis_off ()
271
271
ax .set_navigate (False )
272
+
272
273
self .connect_event ("button_press_event" , self ._update )
273
274
self .connect_event ("button_release_event" , self ._update )
274
275
if dragging :
@@ -329,8 +330,9 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt=None,
329
330
closedmin = True , closedmax = True , slidermin = None ,
330
331
slidermax = None , dragging = True , valstep = None ,
331
332
orientation = 'horizontal' , * , initcolor = 'r' ,
332
- handle_color_grabbed = None , handle_color_released = 'white' ,
333
- handle_edgecolor = '.75' , handle_size = 10 , ** kwargs ):
333
+ bkd_color = 'grey' , handle_color_grabbed = None ,
334
+ handle_color_released = 'white' , handle_edgecolor = '.75' ,
335
+ handle_size = 10 , ** kwargs ):
334
336
"""
335
337
Parameters
336
338
----------
@@ -381,6 +383,10 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt=None,
381
383
The color of the line at the *valinit* position. Set to ``'none'``
382
384
for no line.
383
385
386
+ bkd_color : color, default: 'grey'
387
+ The background color of the slider. The background is accesible for
388
+ further styling via the *bkd* attribute.
389
+
384
390
handle_color_grabbed : color or None, default: None
385
391
The color of the circular slider handle when grabbed. If *None*
386
392
the same color as active part of the slider will be used.
@@ -418,26 +424,17 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt=None,
418
424
self .val = valinit
419
425
self .valinit = valinit
420
426
if orientation == 'vertical' :
427
+ self .bkd = Rectangle ((.25 , 0 ), .5 , 1 , transform = ax .transAxes , facecolor = bkd_color )
428
+ ax .add_patch (self .bkd )
421
429
self .poly = ax .axhspan (valmin , valinit , .25 , .75 , ** kwargs )
422
430
self .hline = ax .axhline (valinit , .25 , .75 , color = initcolor , lw = 1 )
423
431
handleXY = [[0.5 ], [valinit ]]
424
- self ._above_rect = Rectangle (
425
- (0.25 , valinit ),
426
- height = valmax - valinit ,
427
- width = 0.5 ,
428
- transform = ax .get_yaxis_transform (),
429
- )
430
432
else :
433
+ self .bkd = Rectangle ((0 , .25 ), 1 , .5 , transform = ax .transAxes , facecolor = bkd_color )
434
+ ax .add_patch (self .bkd )
431
435
self .poly = ax .axvspan (valmin , valinit , .25 , .75 , ** kwargs )
432
436
self .vline = ax .axvline (valinit , .25 , .75 , color = initcolor , lw = 1 )
433
437
handleXY = [[valinit ], [0.5 ]]
434
- self ._above_rect = Rectangle (
435
- (valinit , 0.25 ),
436
- width = valmax - valinit ,
437
- height = 0.5 ,
438
- transform = ax .get_xaxis_transform (),
439
- )
440
- self ._above_rect .set_facecolor ('grey' )
441
438
self ._handle , = ax .plot (
442
439
* handleXY ,
443
440
"o" ,
@@ -446,7 +443,6 @@ def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt=None,
446
443
markerfacecolor = handle_color_released ,
447
444
clip_on = False
448
445
)
449
- ax .add_patch (self ._above_rect )
450
446
451
447
self ._handle_color_released = handle_color_released
452
448
self ._handle_edgecolor = handle_edgecolor
@@ -551,14 +547,10 @@ def set_val(self, val):
551
547
if self .orientation == 'vertical' :
552
548
xy [1 ] = .25 , val
553
549
xy [2 ] = .75 , val
554
- self ._above_rect .set_y (val )
555
- self ._above_rect .set_height (self .valmax - val )
556
550
self ._handle .set_ydata ([val ])
557
551
else :
558
552
xy [2 ] = val , .75
559
553
xy [3 ] = val , .25
560
- self ._above_rect .set_x (val )
561
- self ._above_rect .set_width (self .valmax - val )
562
554
self ._handle .set_xdata ([val ])
563
555
self .poly .xy = xy
564
556
self .valtext .set_text (self ._format (val ))
@@ -614,6 +606,7 @@ def __init__(
614
606
dragging = True ,
615
607
valstep = None ,
616
608
orientation = "horizontal" ,
609
+ bkd_color = 'grey' ,
617
610
handle_color_grabbed = None ,
618
611
handle_color_released = 'white' ,
619
612
handle_edgecolor = '.75' ,
@@ -658,6 +651,10 @@ def __init__(
658
651
orientation : {'horizontal', 'vertical'}, default: 'horizontal'
659
652
The orientation of the slider.
660
653
654
+ bkd_color : color, default: 'grey'
655
+ The background color of the slider. The background is accesible for
656
+ further styling via the *bkd* attribute.
657
+
661
658
handle_color_grabbed : color or None, default: None
662
659
The color of the circular slider handles when grabbed. If *None*
663
660
the same color as active part of the slider will be used.
@@ -692,41 +689,23 @@ def __init__(
692
689
self .val = valinit
693
690
self .valinit = valinit
694
691
if orientation == "vertical" :
692
+ self .bkd = Rectangle ((.25 , 0 ), .5 , 2 ,
693
+ transform = ax .transAxes ,
694
+ facecolor = bkd_color
695
+ )
696
+ ax .add_patch (self .bkd )
695
697
self .poly = ax .axhspan (valinit [0 ], valinit [1 ], 0 , 1 , ** kwargs )
696
698
handleXY_1 = [.5 , valinit [0 ]]
697
699
handleXY_2 = [.5 , valinit [1 ]]
698
- self ._above_rect = Rectangle (
699
- (.25 , valinit [1 ]),
700
- height = valmax - valinit [1 ],
701
- width = 0.5 ,
702
- transform = ax .get_yaxis_transform (),
703
- )
704
- self ._below_rect = Rectangle (
705
- (valmin , 0.25 ),
706
- width = valinit [0 ] - valmin ,
707
- height = 0.5 ,
708
- transform = ax .get_xaxis_transform (),
709
- )
710
700
else :
701
+ self .bkd = Rectangle ((0 , .25 ), 1 , .5 ,
702
+ transform = ax .transAxes ,
703
+ facecolor = bkd_color
704
+ )
705
+ ax .add_patch (self .bkd )
711
706
self .poly = ax .axvspan (valinit [0 ], valinit [1 ], 0 , 1 , ** kwargs )
712
707
handleXY_1 = [valinit [0 ], .5 ]
713
708
handleXY_2 = [valinit [1 ], .5 ]
714
- self ._above_rect = Rectangle (
715
- (valinit [1 ], 0.25 ),
716
- width = valmax - valinit [1 ],
717
- height = 0.5 ,
718
- transform = ax .get_xaxis_transform (),
719
- )
720
- self ._below_rect = Rectangle (
721
- (valmin , 0.25 ),
722
- width = valinit [0 ] - valmin ,
723
- height = 0.5 ,
724
- transform = ax .get_xaxis_transform (),
725
- )
726
- self ._above_rect .set_facecolor ('grey' )
727
- self ._below_rect .set_facecolor ('grey' )
728
- ax .add_patch (self ._above_rect )
729
- ax .add_patch (self ._below_rect )
730
709
self ._handles = [
731
710
ax .plot (
732
711
* handleXY_1 ,
@@ -934,18 +913,12 @@ def set_val(self, val):
934
913
xy [2 ] = .75 , val [1 ]
935
914
xy [3 ] = .75 , val [0 ]
936
915
xy [4 ] = .25 , val [0 ]
937
- self ._above_rect .set_height (self .valmax - val [1 ])
938
- self ._above_rect .set_y (val [1 ])
939
- self ._below_rect .set_height (val [0 ] - self .valmin )
940
916
else :
941
917
xy [0 ] = val [0 ], .25
942
918
xy [1 ] = val [0 ], .75
943
919
xy [2 ] = val [1 ], .75
944
920
xy [3 ] = val [1 ], .25
945
921
xy [4 ] = val [0 ], .25
946
- self ._above_rect .set_width (self .valmax - val [1 ])
947
- self ._above_rect .set_x (val [1 ])
948
- self ._below_rect .set_width (val [0 ] - self .valmin )
949
922
self .poly .xy = xy
950
923
self .valtext .set_text (self ._format (val ))
951
924
if self .drawon :
0 commit comments