Skip to content

Instantly share code, notes, and snippets.

@amrakm
Forked from jdbcode/get-hex-colors.py
Created July 1, 2021 09:30
Show Gist options
  • Save amrakm/479270c2d1c0f7f714ea2950a22dad5f to your computer and use it in GitHub Desktop.
Save amrakm/479270c2d1c0f7f714ea2950a22dad5f to your computer and use it in GitHub Desktop.
Get a list of n hex colors for a given matplotlib palette
# Source: https://stackoverflow.com/a/33597599/5391200
from pylab import *
cmap = cm.get_cmap('seismic', 5) # matplotlib color palette name, n colors
for i in range(cmap.N):
rgb = cmap(i)[:3] # will return rgba, we take only first 3 so we get rgb
print(matplotlib.colors.rgb2hex(rgb))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment