Convert colors back and forth between string, RGB and HEX

Hi, thanks for a great library.

I have several plots, some are created with other libraries like folium and I need to make colors consistent across them.

In ‘folium’ we are using strings for colors (“red”, “blue”, …) and I need to create an array that displays elements with the same colors (a 2D array or 3D with RGB would be ok). Is there an easy way to convert back and forth between string, RGB and HEX representation fo a color?

Thanks again

Hi

I think you would need to spend some time creating a dataframe containing all the different values like this table here for whatever colours you need:

If not you can take a look at packages that help to convert rgb to hex easily or write something similar to this for your need:

https://webcolors.readthedocs.io/en/1.7/contents.html#webcolors.rgb_to_hex

@sparkmaddy thanks for that solution. I somehow failed to find such package!