import ee
from matplotlib import pyplot as plt
from matplotlib import colors
[docs]def getPalette(name = 'viridis',N = 20,reverse = False):
'''Gets a color palette from a matplotlib colormap.
Parameters
----------
name : string, default = 'viridis'
Name of the matplotlib colormap.
N : int, default = 20
Number of RGB quantization levels.
reverse : boolean, default = False
Whether to invert the color palette. This can also be achieved by adding '_r' to the matplotlib colormap name (e.g. 'viridis_r').
Returns
-------
list
Ready-to-use color palette in hex format.
'''
colormap = plt.get_cmap(name,N)
palette = []
for i in range(colormap.N):
rgba = colormap(i)
palette.append(colors.rgb2hex(rgba))
if reverse:
palette.reverse()
return palette