MATLAB: Create black line on colorbar to mark specific value

colorbarcontourelevationguiguidemanipulation

Hi again.
I have been working on a GUI that creates a contour depending on certain slider values.
I have elevated a specific isoline in the contour by marking it black.
Is it possible to elevate the corresponding position on the colorbar? I have uploaded two images. The first one shows the contour as it is, the second one shows it as I would like it to be, with the colorbar elevation added manually by hand:
Here is the code for my contour (p_nb is the value of the elevated isoline):
contour(handles.SKosten,x1,x1,p_sk,'LevelStep',2,'Fill','on')
hold on
contour(handles.SKosten,x1,x1,p_sk, [p_nb p_nb], 'Color','k','LineWidth',1.45)
And here's the code for the colormap:
b = [.091 .153 0;...
.114 .159 0;...
.137 .166 .001;...
.160 .172 .001;...
.184 .178 .001;...
.207 .184 .001;...
.230 .191 .002;...
.253 .197 .002;...
.253 .181 .003;...
.253 .166 .005;...
.253 .150 .006;...
.254 .134 .007;...
.254 .118 .008;...
.254 .103 .010;...
.254 .087 .011];
b = b*1000;
b = b/255;
caxis([20 50]);
cmp = colormap(b);
cbr = colorbar;
set(cbr,'YTick',20:2:50,'FontSize',9)
b actually changes with a switch (depending on the value of p_nb), so that the inside of the elevated isoline is always green and the outside always yellow/red. I think it would be too much to post the whole thing here, but knowing that could be relevant..
Thanks in advance!
Marc

Best Answer

Good Monday morning brain stimulator!
% Level we care about
level = 0;
% Plot and store colorbar handles
contourf(peaks,-3:3);
hCbar = colorbar;
% Add line to colorbar
line('parent',hCbar,'xdata',[-5 5],...
'ydata',[level level],'color','k','LineWidth',3)
% Note you'll have to swap x/ydata for a horizontal colorbar
% Plot a second contour plot with just the level we care about. Make it
% transparent with a nice thick line
hold on
[~,hCont] = contourf(peaks,[level level]); %contour handles
set(allchild(hCont),'FaceAlpha',0,...
'LineWidth',3,'EdgeColor','k'); %children are patches