Do you know what are the hex codes or RGB values of the "tab" palette (the default 10 colors: tab:blue, tab:orange, etc...) of matplotlib ?
And possibly do you know how if there's a way to obtain the hex code for any named color in matplotlib ?
Turns out this piece of code from the matplotlib examples gave me the answer I was after.
The hex codes of the "tableau" palette are as follows:
tab:blue : #1f77b4
tab:orange : #ff7f0e
tab:green : #2ca02c
tab:red : #d62728
tab:purple : #9467bd
tab:brown : #8c564b
tab:pink : #e377c2
tab:gray : #7f7f7f
tab:olive : #bcbd22
tab:cyan : #17becf
Using the following code I made a dictionnary containing all the named colors and their respective hex code :
import matplotlib.colors as mcolors
mcolors.TABLEAU_COLORS
mcolors.XKCD_COLORS
mcolors.CSS4_COLORS
#Base colors are in RGB so they need to be converted to HEX
BASE_COLORS_hex = {name:mcolors.rgb2hex(color) for name,color in mcolors.BASE_COLORS.items()}
all_named_colors = {}
all_named_colors.update(mcolors.TABLEAU_COLORS)
all_named_colors.update(BASE_COLORS_hex)
all_named_colors.update(mcolors.CSS4_COLORS)
all_named_colors.update(mcolors.XKCD_COLORS)
#print(all_named_colors)
print(all_named_colors["tab:blue"])
>>> #1f77b4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With