To extract html color codes from a seaborn palette, a solution is to use the method as_hex():
>>> import seaborn as sns
>>> pal = sns.color_palette("Blues")
>>> print(pal.as_hex())
returns
['#dbe9f6', '#bad6eb', '#89bedc', '#539ecd', '#2b7bba', '#0b559f']
Hexadecimal code can be then be use in a matplotlib figure fro example:
import matplotlib.pyplot as plt
import numpy as np
x_min = 0.0
x_max = 12.0
x = np.linspace(x_min, x_max, 100)
y = np.linspace(x_min, x_max, 100)
plt.plot(x,y, color='black')
plt.xlim(0,12)
plt.ylim(0,12)
plt.title("How to extract code color from a seaborn palette ?",fontsize=10)
ptx = np.linspace(0, 2, 10)
pty = ptx
plt.fill_between(ptx, pty, color='#dbe9f6', alpha='1.0')
ptx = np.linspace(2, 4, 10)
pty = ptx
plt.fill_between(ptx, pty, color='#bad6eb', alpha='1.0')
ptx = np.linspace(4, 6, 10)
pty = ptx
plt.fill_between(ptx, pty, color='#89bedc', alpha='1.0')
ptx = np.linspace(6, 8, 10)
pty = ptx
plt.fill_between(ptx, pty, color='#539ecd', alpha='1.0')
ptx = np.linspace(8, 10, 10)
pty = ptx
plt.fill_between(ptx, pty, color='#2b7bba', alpha='1.0')
ptx = np.linspace(10, 12, 10)
pty = ptx
plt.fill_between(ptx, pty, color='#0b559f', alpha='1.0')
plt.savefig("extract_seaborn_palette.png")
plt.show()
References
Links | Site |
---|---|
seaborn color palette | seaborn |
Python - sns.color_palette output to Hex number for Bokeh | stackoverflow |
Extract RGB or 6 digit code from Seaborn palette | stackoverflow |
seaborn sequential color palettes | seaborn |