Why aren't my colorbar limits set correctly when I place a colorbar on a CONTOURF plot?

5 views (last 30 days)
There appears to be a problem with the way COLORBAR limits are assigned when using a colorbar with the CONTOURF function. Typing the following for a CONTOURF plot displays a wrong color code.
colorbar
I have to create the right color code by hand. For example,
figure(1)
axes
hold on
imagesc([0 10],[0 6000],linspace(0,1,1000)')
axis([0 10 0 6000])
set(gca,'layer','top','pos',[.92 .725 .03 .2],...
'box','on','ygrid','on',...
'YTick',[0 2000 4000 6000],...
'YAxisLocation','right',...
'xtick',[])
title('Metres')
Is there any chance of getting colorbar to do this by itself?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
The COLORBAR sets its range based on the value of the CLIM property which can be set with the CAXIS command. In the case of CONTOURF, the color limits of the plot do not span the entire range of data. You can use CAXIS to change this. Once you have changed this, you should issue the COLORBAR command again.
You can find more information on the CAXIS command by typing
help caxis
at the MATLAB command prompt.
Note: In MATLAB 7 and above you would need to use
contourf('v6',<data>);
instead of the usual CONTOURF function in order for this workaround to work.

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!