@@ -419,6 +419,7 @@ def interactive_scatter(
419
419
c = None ,
420
420
vmin = None ,
421
421
vmax = None ,
422
+ vmin_vmax = None ,
422
423
alpha = None ,
423
424
marker = None ,
424
425
edgecolors = None ,
@@ -452,6 +453,9 @@ def interactive_scatter(
452
453
or any slider shorthand to control with a slider, or an indexed controls
453
454
object to use an existing slider, or an arbitrary function of the other
454
455
parameters.
456
+ vmin_vmax : tuple of float
457
+ Used to generate a range slider for vmin and vmax. Should be given in range slider
458
+ notation: `("r", 0, 1)`.
455
459
alpha : float or Callable, optional
456
460
Affects all scatter points. This will compound with any alpha introduced by
457
461
the ``c`` argument
@@ -516,21 +520,38 @@ def interactive_scatter(
516
520
facecolors = kwargs .pop ("facecolor" , facecolors )
517
521
edgecolors = kwargs .pop ("edgecolor" , edgecolors )
518
522
519
- kwargs , collection_kwargs = kwarg_popper (kwargs , collection_kwargs_list )
520
-
521
523
ipympl = notebook_backend () or force_ipywidgets
522
524
fig , ax = gogogo_figure (ipympl , ax )
523
525
slider_formats = create_slider_format_dict (slider_formats )
524
526
525
- extra_ctrls = []
526
- funcs , extra_ctrls , param_excluder = prep_scalars (kwargs , s = s , alpha = alpha , marker = marker )
527
+ kwargs , collection_kwargs = kwarg_popper (kwargs , collection_kwargs_list )
528
+ funcs , extra_ctrls , param_excluder = prep_scalars (
529
+ kwargs , s = s , alpha = alpha , marker = marker , vmin = vmin , vmax = vmax
530
+ )
527
531
s = funcs ["s" ]
532
+ vmin = funcs ["vmin" ]
533
+ vmax = funcs ["vmax" ]
528
534
alpha = funcs ["alpha" ]
529
535
marker = funcs ["marker" ]
530
536
537
+ if vmin_vmax is not None :
538
+ if isinstance (vmin_vmax , tuple ) and not isinstance (vmin_vmax [0 ], str ):
539
+ vmin_vmax = ("r" , * vmin_vmax )
540
+ kwargs ["vmin_vmax" ] = vmin_vmax
541
+
531
542
controls , params = gogogo_controls (
532
543
kwargs , controls , display_controls , slider_formats , play_buttons , extra_ctrls
533
544
)
545
+ if vmin_vmax is not None :
546
+ params .pop ("vmin_vmax" )
547
+ params ["vmin" ] = controls .params ["vmin" ]
548
+ params ["vmax" ] = controls .params ["vmax" ]
549
+
550
+ def vmin (** kwargs ):
551
+ return kwargs ["vmin" ]
552
+
553
+ def vmax (** kwargs ):
554
+ return kwargs ["vmax" ]
534
555
535
556
def update (params , indices , cache ):
536
557
if parametric :
@@ -545,7 +566,7 @@ def update(params, indices, cache):
545
566
s_ = check_callable_xy (s , x_ , y_ , param_excluder (params , "s" ), cache )
546
567
ec_ = check_callable_xy (edgecolors , x_ , y_ , param_excluder (params ), cache )
547
568
fc_ = check_callable_xy (facecolors , x_ , y_ , param_excluder (params ), cache )
548
- a_ = check_callable_alpha ( alpha , param_excluder (params , "alpha" ), cache )
569
+ a_ = ( callable_else_value_no_cast ( alpha , param_excluder (params , "alpha" ), cache ), )
549
570
marker_ = callable_else_value_no_cast (marker , param_excluder (params ), cache )
550
571
551
572
if marker_ is not None :
@@ -576,6 +597,10 @@ def update(params, indices, cache):
576
597
scatter .set_sizes (s_ )
577
598
if a_ is not None :
578
599
scatter .set_alpha (a_ )
600
+ if isinstance (vmin , Callable ):
601
+ scatter .norm .vmin = callable_else_value (vmin , param_excluder (params , "vmin" ), cache )
602
+ if isinstance (vmax , Callable ):
603
+ scatter .norm .vmax = callable_else_value (vmax , param_excluder (params , "vmax" ), cache )
579
604
580
605
update_datalim_from_bbox (
581
606
ax , scatter .get_datalim (ax .transData ), stretch_x = stretch_x , stretch_y = stretch_y
@@ -592,14 +617,6 @@ def check_callable_xy(arg, x, y, params, cache):
592
617
else :
593
618
return arg
594
619
595
- def check_callable_alpha (alpha_ , params , cache ):
596
- if isinstance (alpha_ , Callable ):
597
- if alpha_ not in cache :
598
- cache [alpha_ ] = alpha_ (** param_excluder (params , "alpha" ))
599
- return cache [alpha_ ]
600
- else :
601
- return alpha_
602
-
603
620
p = param_excluder (params )
604
621
if parametric :
605
622
out = callable_else_value_no_cast (x , p )
@@ -612,17 +629,16 @@ def check_callable_alpha(alpha_, params, cache):
612
629
s_ = check_callable_xy (s , x_ , y_ , param_excluder (params , "s" ), {})
613
630
ec_ = check_callable_xy (edgecolors , x_ , y_ , p , {})
614
631
fc_ = check_callable_xy (facecolors , x_ , y_ , p , {})
615
- a_ = check_callable_alpha (alpha , params , {})
616
632
marker_ = callable_else_value_no_cast (marker , p , {})
617
633
scatter = ax .scatter (
618
634
x_ ,
619
635
y_ ,
620
636
c = c_ ,
621
637
s = s_ ,
622
- vmin = vmin ,
623
- vmax = vmax ,
638
+ alpha = callable_else_value_no_cast (alpha , param_excluder (params , "alpha" )),
639
+ vmin = callable_else_value_no_cast (vmin , param_excluder (params , "vmin" )),
640
+ vmax = callable_else_value_no_cast (vmax , param_excluder (params , "vmax" )),
624
641
marker = marker_ ,
625
- alpha = a_ ,
626
642
edgecolors = ec_ ,
627
643
facecolors = fc_ ,
628
644
label = label ,
0 commit comments