@@ -690,15 +690,16 @@ def colorize(self, values: dict, **kwargs) -> _volume.Volume:
690
690
name = f"Custom colorization of { self } "
691
691
)
692
692
693
- def get_colormap (self , region_specs : Iterable = None , * , allow_random_colors : bool = False ):
693
+ def get_colormap (self , region_specs : Iterable = None , * , fill_uncolored : bool = False ):
694
694
"""
695
695
Generate a matplotlib colormap from known rgb values of label indices.
696
696
697
697
Parameters
698
698
----------
699
699
region_specs: iterable(regions), optional
700
700
Optional parameter to only color the desired regions.
701
- allow_random_colors: bool , optional
701
+ fill_uncolored: bool , optional
702
+ If a region has no preconfigured color, a color will be randomly (reproducible) created.
702
703
703
704
Returns
704
705
-------
@@ -711,7 +712,7 @@ def get_colormap(self, region_specs: Iterable = None, *, allow_random_colors: bo
711
712
"matplotlib not available. Please install matplotlib to create a matplotlib colormap."
712
713
)
713
714
raise e
714
- if allow_random_colors :
715
+ if fill_uncolored :
715
716
seed = len (self .regions )
716
717
np .random .seed (seed )
717
718
logger .info (f"Random colors are allowed for regions without preconfgirued colors. Random seee: { seed } ." )
@@ -724,6 +725,7 @@ def get_colormap(self, region_specs: Iterable = None, *, allow_random_colors: bo
724
725
else :
725
726
include_region_names = None
726
727
728
+ no_predefined_color = []
727
729
for regionname , indices in self ._indices .items ():
728
730
for index in indices :
729
731
if index .label is None :
@@ -735,16 +737,25 @@ def get_colormap(self, region_specs: Iterable = None, *, allow_random_colors: bo
735
737
region = self .get_region (index = index )
736
738
if region .rgb is not None :
737
739
colors [index .label ] = region .rgb
738
- elif allow_random_colors :
740
+ elif fill_uncolored :
739
741
random_clr = [np .random .randint (0 , 255 ) for r in range (3 )]
740
742
while random_clr in list (colors .values ()):
741
743
random_clr = [np .random .randint (0 , 255 ) for r in range (3 )]
742
744
colors [index .label ] = random_clr
745
+ else :
746
+ no_predefined_color .append (region .name )
743
747
744
748
if len (colors ) == 0 :
745
749
raise exceptions .NoPredifinedColormapException (
746
750
f"There is no predefined/preconfigured colormap for '{ self } '."
747
- "Set `allow_random_colors=True` to a colormap with random values"
751
+ "Set `fill_uncolored=True` to get a reproducible colormap."
752
+ )
753
+
754
+ if no_predefined_color :
755
+ logger .info (
756
+ f"No preconfigured color found for the follwing regions."
757
+ "Use `fill_uncolored=True` to display with a non-background color.\n "
758
+ f"{ no_predefined_color } "
748
759
)
749
760
750
761
palette = np .array (
0 commit comments