def show_palette():
import matplotlib.pyplot as plt
colors = {'#FF0000': 'red',
'#00FF00': 'green',
'#0000FF': 'blue',
'#FFFF00': 'orange',
'#FF00FF': 'pink',
'#00FFFF': 'cyan',
(0,255/255,128/255): 'color1'
}
fig, ax = plt.subplots(figsize=(6, 5))
for i, (color, name) in enumerate(colors.items()):
ax.axhspan(i*5, i*5 + 5.8, color=color, alpha=1)
ax.text(0, i*5 + 1.9, name, va='center', fontsize=12)
ax.set_xlim(0, 5)
ax.set_ylim(0, len(colors) * 5)
ax.set_xticklabels([])
ax.set_xticks([])
ax.set_yticklabels([])
ax.set_yticks([])
plt.savefig('palette.png')
plt.show()
if __name__ == '__main__':
show_palette()
效果图如下: