How to change a ‘LinearSegmentedColormap’ to a different distribution of color?

When making colormaps with LinearSegmentedColormap.from_list, you can supply a list of tuples of the form (value, color) (as opposed to simply a list of colors) where the values correspond to the relative positions of colors. The values must range from 0 to 1 so you will have to supply an intermediate color. In your case I might try this,

cmap = clr.LinearSegmentedColormap.from_list('custom blue', 
                                             [(0,    '#ffff00'),
                                              (0.25, '#002266'),
                                              (1,    '#002266')], N=256)

and tweak color/value until satisfied. Credit goes to https://stackoverflow.com/a/25000108/5285918

Leave a Comment