@@ -1342,7 +1342,7 @@ def _make_plot(self, fig: Figure) -> None:
1342
1342
# colored by uniqueness of the strings, such same strings get same color
1343
1343
create_colors = not self ._are_valid_colors (c_values )
1344
1344
if create_colors :
1345
- color_mapping , c_values = self ._uniquely_color_strs (c_values )
1345
+ custom_color_mapping , c_values = self ._uniquely_color_strs (c_values )
1346
1346
cb = False # no colorbar; opt for legend
1347
1347
1348
1348
if self .legend :
@@ -1380,7 +1380,7 @@ def _make_plot(self, fig: Figure) -> None:
1380
1380
ax .legend (
1381
1381
handles = [
1382
1382
mpl .patches .Circle ((0 , 0 ), facecolor = color , label = string )
1383
- for string , color in color_mapping .items ()
1383
+ for string , color in custom_color_mapping .items ()
1384
1384
]
1385
1385
)
1386
1386
@@ -1408,7 +1408,7 @@ def _get_c_values(self, color, color_by_categorical: bool, c_is_column: bool):
1408
1408
return c_values
1409
1409
1410
1410
def _are_valid_colors (self , c_values : np .ndarray | list ):
1411
- # check if c_values contains strings and if these strings are valid mpl colors
1411
+ # check if c_values contains strings and if these strings are valid mpl colors.
1412
1412
# no need to check numerics as these (and mpl colors) will be validated for us
1413
1413
# in .Axes.scatter._parse_scatter_color_args(...)
1414
1414
try :
@@ -1424,10 +1424,16 @@ def _uniquely_color_strs(
1424
1424
self , c_values : np .ndarray | list
1425
1425
) -> tuple [dict , np .ndarray ]:
1426
1426
# well, almost uniquely color them (up to 949)
1427
- possible_colors = list (mpl .colors .XKCD_COLORS .values ()) # Hex representations
1428
- shuffle (possible_colors ) # TODO: find better way of getting colors
1429
-
1430
1427
unique = np .unique (c_values )
1428
+
1429
+ # for up to 7, lets keep colors consistent
1430
+ if len (unique ) <= 7 :
1431
+ possible_colors = list (mpl .colors .BASE_COLORS .values ()) # Hex
1432
+ # explore better ways to handle this case
1433
+ else :
1434
+ possible_colors = list (mpl .colors .XKCD_COLORS .values ()) # Hex
1435
+ shuffle (possible_colors )
1436
+
1431
1437
colors = [possible_colors [i % len (possible_colors )] for i in range (len (unique ))]
1432
1438
color_mapping = dict (zip (unique , colors ))
1433
1439
0 commit comments