File Exchange

image thumbnail

cbarrow: pointy ends for colorbars

version 1.1.0.0 (393 KB) by Chad Greene
Make pointed ends for colorbars

29 Downloads

Updated 17 Jun 2016

View Version History

View License

This function makes pointed ends for colorbars to indicated that values have been clipped.

Cite As

Chad Greene (2021). cbarrow: pointy ends for colorbars (https://www.mathworks.com/matlabcentral/fileexchange/52515-cbarrow-pointy-ends-for-colorbars), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (16)

Jakob Weis

Works great. A made one small modification for aesthetics:
cb.Box = 'off' (line 195) removes the box around the original colourbar, but the line along the main colourbar axis remains. The newly created outline is aligned below this axis line and therefore results in a thicker edge (2x the original line width). This issue can easily be fixed by shifting the outline and stretching the colourbar upwards* by the line width. The stretching is necessary, since the shift is creating a small line of white space which needs to be filled. I added the following lines of code after line 244 (axis([0 1 0 1])) to implement this fix:

set(gca,'Units','points'); % change new outline units to points
cbpos = get(gca,'Position'); % get outline position
set(gca,'Position',[cbpos(1),cbpos(2)+linewidth,cbpos(3),cbpos(4)]) % shift outline position upwards by the linewidth
set(cb,'Units','points'); % change colour bar units to points
cb.Position(4) = cb.Position(4)+linewidth; % stretch colourbar vertically upwards by the linewidth

*for horizontal colour bars with a bottom-aligned axis, fix would have to be implemented for every case (i.e. left/right/up/bottom-aligned colourbar axes)

edward kabanyas

How to use it in sublot? I tried but the cbarrow only work for the last plot

BN2

Dear all,
I have a problem using this function. After I use it the color bar get extremely thick and locates far away from my figure. Here is the link of my question:
https://www.mathworks.com/matlabcentral/answers/523579-colorbar-appears-in-far-away-from-figure-and-very-thick
Thank you

joey wang

Jing Ci Neo

Huang Yan

Thanks!

tsohau

does the trick!

Will

Will

Excellent function!
A minor fix that I've used to maintain the "figure('visibility', 'off')" setting -- change line 252 "axes(h)" to "set(gcf, 'CurrentAxes', h)", and similar for line 255. Otherwise, an invisible figure becomes visible when you call this function.

qiuping Ren

Thanks!Good job!

Gloria Wang

thanks so much

Aodat

Thanks Chad, works fine!

Chad Greene

Ah, good catch Aodat! Thanks for pointing this out. The bug should be fixed now.

Aodat

Thanks Chad!
I'm experiencing a bug with cbarrow('down').
Example code:
figure; colorbar; cbarrow('down');
Doesn't work properly for me, but shows additional lines. Would be great if you could fix that. Tested with Matlab 2015a & 2015b.

OUC Polar

Thank you so much!

MATLAB Release Compatibility
Created with R2015a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

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

Start Hunting!

cbarrow/

cbarrow/html/