I'd like to generate a colorbar for values stored in a list
def map_values_to_color(data: List, cmap: str, integer=False):
norm = matplotlib.colors.Normalize(vmin=min(data), vmax=max(data), clip=True)
mapper = cm.ScalarMappable(norm=norm, cmap=cmap)
if integer:
color = [[r, g, b] for r, g, b, a in mapper.to_rgba(data, bytes=True)]
else:
color = [[r, g, b] for r, g, b, a in mapper.to_rgba(data)]
colorlist = [(val, color) for val, color in zip(data, color)]
return colorlist
if __name__ == '__main__':
vals = [100, .80, .10, .79, .70, .60, .75, .78, .65, .90]
colorlist = map_values_to_color(data=vals, cmap='bwr_r', integer=True)
Any suggestions on how to generate just the colorbar will be really helpful.
EDIT: Output obtained from the below code:
EDIT2: The below answer might be useful for lists without outliers. However, my data has outliers and I am still looking for suggestions/ inputs on how to visualize the data with outliers efficiently using a colorbar i.e some sort of a discrete colorbar.