File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed
Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -333,16 +333,19 @@ def plot_confusion_matrix(
333333 # Add annotation color bars if colors are available
334334 if show_annotation_colors and labels is not None :
335335 colors_key = f"{ label_key } _colors"
336- # Try to get colors from query first, then reference
336+ # Try to get colors from reference first (source of labels) , then query
337337 colors_dict = None
338- for adata in [self .query , self .reference ]:
338+ for adata in [self .reference , self .query ]:
339339 if adata is not None and colors_key in adata .uns :
340340 # Get full categories and colors from adata
341+ # Colors are stored in same order as .cat.categories
341342 full_categories = adata .obs [label_key ].cat .categories
342343 full_colors = adata .uns [colors_key ]
343- # Handle case where colors list might be shorter (only create dict for available pairs)
344- n_pairs = min (len (full_categories ), len (full_colors ))
345- colors_dict = {str (full_categories [i ]): full_colors [i ] for i in range (n_pairs )}
344+ # Build dict mapping category name -> color
345+ colors_dict = {}
346+ for i , cat in enumerate (full_categories ):
347+ if i < len (full_colors ):
348+ colors_dict [str (cat )] = full_colors [i ]
346349 break
347350
348351 if colors_dict is not None :
You can’t perform that action at this time.
0 commit comments