Skip to content

Instantly share code, notes, and snippets.

@cbur24
Created January 21, 2022 03:25
Show Gist options
  • Save cbur24/e5e5971b02e3c5927126e3b968a3697f to your computer and use it in GitHub Desktop.
Save cbur24/e5e5971b02e3c5927126e3b968a3697f to your computer and use it in GitHub Desktop.
Print hex codes for matplotlib colour ramps
from pylab import *
import numpy as np
n=17
cmap = cm.get_cmap('magma', n)
for i,j in zip(range(cmap.N), np.arange(0,0.425,0.025)):
rgba = cmap(i)
# rgb2hex accepts rgb or rgba
print("{'value': "+str(round(j,3))+", 'color': "+"'"+ matplotlib.colors.rgb2hex(rgba)+"'"+"},")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment