Python - sns.color_palette 输出为散景的十六进制数
Python - sns.color_palette output to Hex number for Bokeh
的输出格式是什么
sns.color_palette('Reds', 5)?
如何将其转换为十六进制数?
运行 上述命令为您提供输出:
[(0.99358708227381987, 0.83234141714432663, 0.76249136363758763), (0.98823529481887817, 0.62614381313323975, 0.50849674145380652), (0.98357554884517895, 0.4127950837799147, 0.28835064675293715), (0.89019608497619629, 0.18562091638644537, 0.15294117977221808), (0.69439448188332953, 0.070034602810354785, 0.092318341048324815)]
如何将其转换为如下所示的输出:
["#9b59b6", "#3498db", "#95a5a6", "#e74c3c", "#34495e", "#2ecc71", "#43A16F"]
Matplotlib 有一个 rgb2hex
函数:
rgb_colors = sns.color_palette('Reds', 5))
hex_colors = list(map(mpl.colors.rgb2hex, rgb_colors)
结果:
['#fdd4c2', '#fca082', '#fb694a', '#e32f27', '#b11218']
更好(假设 seaborn >= 0.6):
import seaborn as sns
pal = sns.color_palette('Reds', 5)
pal.as_hex()
['#fdd4c2', '#fca082', '#fb694a', '#e32f27', '#b11218']
sns.color_palette('Reds', 5)?
如何将其转换为十六进制数?
运行 上述命令为您提供输出:
[(0.99358708227381987, 0.83234141714432663, 0.76249136363758763), (0.98823529481887817, 0.62614381313323975, 0.50849674145380652), (0.98357554884517895, 0.4127950837799147, 0.28835064675293715), (0.89019608497619629, 0.18562091638644537, 0.15294117977221808), (0.69439448188332953, 0.070034602810354785, 0.092318341048324815)]
如何将其转换为如下所示的输出:
["#9b59b6", "#3498db", "#95a5a6", "#e74c3c", "#34495e", "#2ecc71", "#43A16F"]
Matplotlib 有一个 rgb2hex
函数:
rgb_colors = sns.color_palette('Reds', 5))
hex_colors = list(map(mpl.colors.rgb2hex, rgb_colors)
结果:
['#fdd4c2', '#fca082', '#fb694a', '#e32f27', '#b11218']
更好(假设 seaborn >= 0.6):
import seaborn as sns
pal = sns.color_palette('Reds', 5)
pal.as_hex()
['#fdd4c2', '#fca082', '#fb694a', '#e32f27', '#b11218']