contourf colormap from blue to white with gradient

907 views Asked by At

I would like to change the colormap in my plot, from yellow to blue, to be from blue to white;only two colors with gradient. Is it possible?

Code:

x = randn(1000,1);
y = randn(1000,1);
[N,Xedges,Yedges] = histcounts2(x,y);
contourf(N)

any help is more than welcome.

1

There are 1 answers

0
Luis Mendo On BEST ANSWER

You can specify the colormap to be used in the figure with the colormap function. A colormap is just a three-column matrix with values between 0 and 1 representing R,G,B components, so you can create it manually. For example, to produce a simple colormap from blue to white:

N = 256; % number of colors
cmap = [linspace(1,0,N).' linspace(1,0,N).' ones(N,1)]; % decreasing R and G; B = 1
colormap(cmap)

enter image description here

However, this colormap is not perceptually uniform, that is, the perceived "color difference" is not uniform across the full color range. To generate a perceptually uniform colormap from blue to white I suggest the user-contributed BrewerMap function with the 'Blues' option:

N = 256; % number of colors
cmap = brewermap(N, 'Blues');
colormap(cmap)

enter image description here