MATLAB: Do the colors in the color bar of a “contourfm” plot get non-uniformly distributed over the updated range of color axis, when I update the color axis limits using “caxis”

barcaxiscolorcontourcbarcontourfmMATLABnon-uniform

Execute the following commands to generate a contour map:
 
>> figure
>> axesm eckert4; framem; gridm; axis off; tightmap
>> load geoid
>> contourfm(geoid, geoidrefvec, -120:20:100, 'LineStyle', 'none');
>> coast = load('coast');
>> geoshow(coast.lat, coast.long, 'Color', 'black')
>> contourcbar
Now update the color axis limits to a wider range, [-300 300], by executing the following command
 
>> caxis([-300 300])
The colors on the color bar get non-uniformly distributed over the updated range of color axis.
How can these colors be distributed uniformly over the updated range of color axis?

Best Answer

The colors can be distributed uniformly on the color bar by specifying the wider range of the color axis limit within the "contourfm" command as follows:
 
>> contourfm(geoid, geoidrefvec, -300:20:300, 'LineStyle', 'none');
This will ensure a uniform distribution of colors on the color bar when the color axis limits are updated to [-300 300].
Now use "caxis" to change the color axis limits to [-300 300]. It will update both the color bar and the plot accordingly.
 
>> caxis([-300 300])
Also, if a wider range of colors is needed, an appropriate color map can be used, e.g., "jet" can be used by executing the following command:
 
contourcmap jet