Created
January 21, 2022 03:25
-
-
Save cbur24/e5e5971b02e3c5927126e3b968a3697f to your computer and use it in GitHub Desktop.
Print hex codes for matplotlib colour ramps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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