MATLAB: To define the axes for just one subplot colorabar

axesaxiscaxiscolorbar

*For subplot(1,7,5)- I want to define the range of colorabar [0 6]*
subplot(1,7,4)
m_proj('Stereographic','lat',90,'long',300,'radius',35,'rect','on');
m_contourf(long,lat,oct_skw_anom ,'linestyle','none');
m_grid('linewi',1,'tickdir','out',...
'xtick',6,'ytick',[72 76 80 84 88 90]);
m_coast('patch',[.6 .6 .6],'edgecolor','k');
m_elev('contour',[ ],'edgecolor',' ');
colorbar( 'location','southoutside');
subplot(1,7,5)
m_proj('Stereographic','lat',90,'long',300,'radius',35,'rect','on');
m_contourf(long,lat,oct_kts_anom ,'linestyle','none');
m_grid('linewi',1,'tickdir','out',...
'xtick',6,'ytick',[72 76 80 84 88 90]);
m_coast('patch',[.6 .6 .6],'edgecolor','k');
m_elev('contour',[ ],'edgecolor',' ');
caxis = ([0, 6]);
h = colorbar(caxis, 'southoutside');

Best Answer

There are two different things you could mean here.
One is that you want the colormap to start where the data = 0 and end where the data = 6. You actually do that with the axes object, not the colorbar. The colorbar is just showing the mapping that the axes is using.
The subplot command returns a handle to the axes. So you'd want to do something like this:
ax = subplot(1,7,5)
m_proj('Stereographic','lat',90,'long',300,'radius',35,'rect','on');
m_contourf(long,lat,oct_kts_anom ,'linestyle','none');
m_grid('linewi',1,'tickdir','out',...
'xtick',6,'ytick',[72 76 80 84 88 90]);
m_coast('patch',[.6 .6 .6],'edgecolor','k');
m_elev('contour',[ ],'edgecolor',' ');
caxis(ax,[0 6])
colorbar('southoutside')
Note, you had a variable named caxis, that's also the name of the function you use to set the color range on the axes, so you might get a conflict there. You probably want to rename that variable and clear it from your workspace.
The other thing you might mean here is that you only want the colorbar to show a portion of the color range. This won't change the mapping between data values and colors. It's just like "zooming in" on the colorbar. The details of how you do this has changed a bit in the last couple of versions of MATLAB, but in R2016a, you would do this:
c = colorbar('southoutside');
c.Limits = [0 6];
or this:
colorbar('southoutside','Limits',[0 6])
Related Question