Skip to content

Commit 0ed7c3d

Browse files
committed
Use the actual interface for color names
cf ubernostrum/webcolors@dee9d46 and ubernostrum/webcolors#20 (comment)
1 parent 155dd2a commit 0ed7c3d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/tikzplotlib/_color.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@
2929
def _get_closest_colour_name(rgb):
3030
match = None
3131
mindiff = 1.0e15
32-
hex_names_dict = (
33-
webcolors.CSS3_HEX_TO_NAMES
34-
if hasattr(webcolors, "CSS3_HEX_TO_NAMES")
35-
else webcolors._definitions._CSS3_HEX_TO_NAMES
36-
)
32+
if hasattr(webcolors, "names"):
33+
hex_names_dict = {
34+
webcolors.name_to_hex(name, spec=webcolors.CSS3): name
35+
for name in webcolors.names(spec=webcolors.CSS3)
36+
}
37+
elif hasattr(webcolors, "CSS3_HEX_TO_NAMES"):
38+
hex_names_dict = webcolors.CSS3_HEX_TO_NAMES
39+
else:
40+
hex_names_dict = webcolors._definitions._CSS3_HEX_TO_NAMES
3741
for h, name in hex_names_dict.items():
3842
r = int(h[1:3], 16)
3943
g = int(h[3:5], 16)

0 commit comments

Comments
 (0)