@@ -666,11 +666,16 @@ def show(
666
666
# If any of the previous conditions are not met, generate random
667
667
# colors for each cell id
668
668
669
+ N_DISTINCT_FOR_RANDOM = 30
670
+
669
671
if sdata .table is not None :
670
672
# annoying case since number of cells in labels can be
671
673
# different from number of cells in table. So we just use
672
674
# the index and randomise colours for it
673
675
676
+ # add fake column for limiting the amount of different colors
677
+ sdata .table .obs ["fake" ] = np .random .randint (0 , N_DISTINCT_FOR_RANDOM , sdata .table .obs .shape [0 ])
678
+
674
679
# has a table, so it has a region key
675
680
region_key = _get_region_key (sdata )
676
681
@@ -681,7 +686,7 @@ def show(
681
686
region_key = _get_region_key (sdata )
682
687
instance_key = _get_instance_key (sdata )
683
688
params ["instance_key" ] = instance_key
684
- params ["color_key" ] = instance_key
689
+ params ["color_key" ] = "fake"
685
690
params ["add_legend" ] = False
686
691
# TODO(ttreis) log the decision not to display a legend
687
692
@@ -693,7 +698,7 @@ def show(
693
698
cell_ids_per_label = {}
694
699
for key in list (sdata .labels .keys ()):
695
700
cell_ids_per_label [key ] = sdata .labels [key ].values .max ()
696
-
701
+ print ( cell_ids_per_label )
697
702
region_key = "tmp_label_id"
698
703
instance_key = "tmp_cell_id"
699
704
params ["instance_key" ] = instance_key
@@ -708,10 +713,11 @@ def show(
708
713
}
709
714
)
710
715
716
+ tmp_table ["fake" ] = np .random .randint (0 , N_DISTINCT_FOR_RANDOM , sdata .table .obs .shape [0 ])
711
717
distinct_cells = max (list (cell_ids_per_label .values ()))
712
718
713
719
if sdata .table is not None :
714
- print ("Plotting a lot of cells with random colors, might take a while..." )
720
+ # print("Plotting a lot of cells with random colors, might take a while...")
715
721
sdata .table .uns [f"{ instance_key } _colors" ] = _get_random_hex_colors (distinct_cells )
716
722
717
723
elif sdata .table is None :
0 commit comments