Skip to content Skip to sidebar Skip to footer

Custom Colourmaps In Matplotlib

I'm trying to make my own colourmap in matplotlib but I can't seem to get it to work correctly, the colours it is outputting are not the ones I was expecting I've tried the other s

Solution 1:

I think what you want can be achieved much easier than using this complicated dictionary.

Just create a 2D array which has in the first row the RGB values from the first color, in the second those from the middle color, and in the last row the values from the final color. Then use the matplotlib.colors.LinearSegmentedColormap.from_list function to obtain a colormap.

import numpy as np
import matplotlib.colorscolors= np.array([(0,99,136), (159,161,97), (170,43,74)])/255.
cm = matplotlib.colors.LinearSegmentedColormap.from_list('cm', colors)

enter image description here

Post a Comment for "Custom Colourmaps In Matplotlib"