@@ -1101,9 +1101,15 @@ def _set_color_source_vec(
11011101 processed = processed .reorder_categories (sorted (processed .categories ))
11021102 color_source_vector = processed # convert, e.g., `pd.Series`
11031103
1104+ # When the value lives on the element's own DataFrame (origin="df"),
1105+ # there is no reason to look up a table for .uns colors.
1106+ value_from_element = origins [0 ].origin == "df"
1107+
11041108 # Use the provided table_name parameter, fall back to only one present
11051109 table_to_use : str | None
1106- if table_name is not None and table_name in sdata .tables :
1110+ if value_from_element :
1111+ table_to_use = None
1112+ elif table_name is not None and table_name in sdata .tables :
11071113 table_to_use = table_name
11081114 elif table_name is not None and table_name not in sdata .tables :
11091115 logger .warning (f"Table '{ table_name } ' not found in `sdata.tables`. Falling back to default behavior." )
@@ -1120,14 +1126,18 @@ def _set_color_source_vec(
11201126
11211127 adata_for_mapping = sdata [table_to_use ] if table_to_use is not None else None
11221128
1123- # Check if custom colors exist in the table's .uns slot
1124- if value_to_plot is not None and _has_colors_in_uns (sdata , table_name , value_to_plot ):
1129+ # Check if custom colors exist in the resolved table's .uns slot
1130+ if (
1131+ value_to_plot is not None
1132+ and table_to_use is not None
1133+ and _has_colors_in_uns (sdata , table_to_use , value_to_plot )
1134+ ):
11251135 # Extract colors directly from the table's .uns slot
11261136 # Convert Color to ColorLike (str) for the function
11271137 na_color_like : ColorLike = na_color .get_hex () if isinstance (na_color , Color ) else na_color
11281138 color_mapping = _extract_colors_from_table_uns (
11291139 sdata = sdata ,
1130- table_name = table_name ,
1140+ table_name = table_to_use ,
11311141 col_to_colorby = value_to_plot ,
11321142 color_source_vector = color_source_vector ,
11331143 na_color = na_color_like ,
0 commit comments