Using Python and matplotlib, is there a convenient way to do the following:
Establish a mapping between colors and values, say -5 = black, -2 = red, 0 = white, +2 = blue, +5 = black
Generate a colormap that interpolates between those values, similar to matplotlib.colors.LinearSegmentedColormap.from_list()
Make a pseudocolor plot
pcolormesh(X,Y,Z)
, where 0 < Z < 3 using the color coding established above. This means only a subset of the colormap will be used. (The color red will never be used since there are no negative values.)Add a colorbar ranging from 0 to 3.
This will allow to keep the mapping between values and colors consistent across multiple plots.
LinearSegmentedColormap
and proper limits on your normalization function. Color maps take an argument in[0, 1]
, so your just need to map your values onto that range as you desire. – tacaswell