20 April 2022 13:00
Extract matplotlib colormap in hex-format
import matplotlib
from matplotlib import cm
# See https://stackoverflow.com/a/65677873 for None usage
cmap = cm.get_cmap('Paired', None) # PiYG
print('cmap = n ')
print(cmap)
for i in range(cmap.N):
rgba = cmap(i)
# rgb2hex accepts rgb or rgba
print(matplotlib.colors.rgb2hex(rgba))
1
(1 marks)