-
Notifications
You must be signed in to change notification settings - Fork 856
Description
Hello,
I've stumbled upon a ValueError: invalid literal for int() with base 10 in _select_font_color().
In umap.umap.plot.py line 241:
[int("0x" + c) for c in (background[1:3], background[3:5], background[5:7])]Simply replace int("0x" + c) by int("0x" + c, 0) to interpret the passed string as integer literal to fix the issue:
[int("0x" + c, 0) for c in (background[1:3], background[3:5], background[5:7])]However, I'm not sure if this is some leftover code or if hexadecimal colors are/will be supported.
How this happened
In order to enhance the visibility of a predefined set of label colors I wanted to specify a custom color for the background.
Seeing that umap.plot.points() takes a background argument, I tried to pass a hexadecimal string since color_key works with hexadecimal strings and the docstring states that "any color name will work".
Hence I had hoped that background would also work with hexadecimal strings (even though they are admittedly more of a color definition than a color name).
Unfortunately, it resulted in the aforementioned error.
Workarounds to specify a custom background color
Simply calling ax.set_facecolor() after calling umap.plot.points() does the trick as long as there are not too many datapoints.
Otherwise, in the event datashader kicks in, the following monkey patching solution worked for me (since datashader also supports color tuples):
class CustomTuple(tuple):
def __new__(cls, *values):
return super().__new__(cls, values)
def __init__(self, *values):
self.values = values
def startswith(self, s: str) -> bool:
"""Avoid faulty if-statement."""
return False
bg = CustomTuple(0, 123, 255) # choose whatever color you need
umap.plot.points(..., ax=ax, background=bg)Kind regards