Reputation: 512
How can I make the rectangular line around the box of the colorbar white, but keep the tick labels black?
Reproducible code below:
colormap(flipud(autumn(6))); % Create Colormap
cb = colorbar; % Create Colorbar
cb.Ticks = [.1667 .3334 .5001 .6668 .8335]; % Create ticks
cb.TickLabels = ({'0%','5%','10%','15%','20%'});
cb.TickLength = 0;
cb.Color = 'w'; % Everything becomes white, I only want the rectangular color of the box to be white
Upvotes: 2
Views: 284
Reputation: 24159
From the ColorBar properties documentation page we learn that the Color
property changes too many things:
Color
— Color of tick marks, text, and box outline
So we have to try something else. Fortunately, if you are comfortable with using an undocumented feature, the desired effect can be achieved by modifying the colorbar's Ruler
property:
function [] = q66408322()
hF = figure();
hAx = axes(hF);
colormap(hAx, flipud(autumn(6)));
hCb = colorbar(hAx,...
'Ticks', [.1667 .3334 .5001 .6668 .8335],...
'TickLabels', {'0%','5%','10%','15%','20%'}, ...
'TickLength', 0, ...
'Color', 'w');
hCb.Ruler.Color = 'k'; % <<<<<< Solution
Resulting in:
Upvotes: 3
Reputation: 1325
You could get the wanted visual effect by overlaying a white annotation box on the colorbar, e.g.
colormap(flipud(autumn(6))); % Create Colormap
cb = colorbar; % Create Colorbar
cb.Ticks = [.1667 .3334 .5001 .6668 .8335]; % Create ticks
cb.TickLabels = ({'0%','5%','10%','15%','20%'});
cb.TickLength = 0;
% cb.Color = 'w'; % Everything becomes white, I only want the rectangular color of the box to be white
annotation('rectangle',cb.Position,'Color','w','FaceColor','none','LineWidth',2)
Upvotes: 3