Code covered by the BSD License  

Highlights from
cbarf

4.66667

4.7 | 9 ratings Rate this file 32 Downloads (last 30 days) File Size: 3.37 KB File ID: #14290
image thumbnail

cbarf

by M MA

 

15 Mar 2007 (Updated 14 May 2008)

Real filled colorbar

| Watch this File

File Information
Description

Similar to the well known colorbarf but more realistic.

There are two things missing in colorbar and colorbarf:
1. the colorbar ticks are scaled according to the size of each interval.
2. when color is saturated at the upper limit, or when is white, below the lower limit, a triangle is added. The triangle means "more/less than". Such information is not provided by the existing tools, colorbar and colorbarf.
See the examples.

Besides, there is a bug (?) with contourf: in some cases, even with the levels specified, one additional level is added and corrensponds to the sourrounding line! In such case, colorbarf adds one box for this fake level!

Syntax: H=CBARF(DATA,LEVELS,MODE,SCALE)

Updated 13-7-2007 by adding the option SCALE for linear/non linear scale

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
colorbarf

MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (16)
04 Jun 2007 Loic Jullion

Great!Exactly what I needed!

19 Jul 2007 Lucio Rezende

grande martinho ! excelente !

02 May 2008 K Kats

I have been thinking about switching to another tool for contour plots, but this neat script saved me! Thank you.

14 May 2008 wu only

Thank u for your work!
but I also find a bug(?) with it.

cbarf(data,lev,'vertical','nonlinear') and
cbarf(data,lev,'vertical','linear') produce different colors according to the same specified levels. The latter one is right.

14 May 2008 M MA

You are right Wu. The bug is now fixed.
Thank you

22 May 2008 Wu Zhiyong

Great work! Thank you!

06 May 2009 Brian Magi

A really useful function for a much better colorbar option. This is probably a simple change, but i don't know enough about handle graphics. When i change the position of the colorbar from cbarf to somewhere in the plot, cbarf is always behind the main plot. I tried changing 'Layer' to top (and the main plot to bottom) but to no avail. if anyone has what is probably a quick solution, i'd appreciate it.

29 Sep 2009 Chamane

great work!

29 Nov 2009 Joseph MacGregor

Works as advertised. I used it to produce a discretely sampled (rather than continuous) colorbar for a contourf figure. The resulting colorbar didn't behave ideally after an axes position shift, but I was able to cheat by two copies of the figure (one with a continuous colorbar and the other discrete) and copy/pasting the discrete colorbar onto the better behaved continuous figure. I didn't need the third and fourth inputs. Honestly, it seems like it should be able to work with just the second input (LEVELS) somehow...

Thanks very much for producing this script.

21 Jun 2010 Manoj

Excellent job, but it always get behind the plot on printing or saving. Need to fix it.

24 Jun 2010 Makarand

I have one problem, can we use it with pcolor
I tried it to use with pcolor as follows
%%%%
X=1:10;Y=1:10;
C=rand(10,10)*150;
colormap(jet);
L=[10 20 50 60 70 100];
contourf(X,Y,C,L);
pcolor(X,Y,C);
cbarf(C,L);
%%%%%%%%%%%%%%
The yellow (an extra) color is there on plot but not in the colorbar.
I have one more question: is it possible to equally space the colors in the colorbar

02 Jul 2010 Manoj

When I use HSV colormap the lowest and highest value band getting same color.

02 Jul 2010 Manoj

Oh that's default not bug of cbarf. HSV has circular colour pattern.

27 Jul 2011 Sam

When I use cbarf the levels are not labeled on the colorbar. I have levels -0.5:0.1:0.5. and for some reason only 0.2 is labeled. Any suggestions on how to correct this? Other than that, this is a great tool. Exactly what I have been looking for.

30 Nov 2011 Christopher Wolfe

I have the same problem as Sam. It's due to the use of yt=intersect(yt,L(a:b+1)) on line 214 to select the labels. Somehow rounding errors can make yt and L different by as small multiple of eps, so these labels are excluded by intersect. I work around it by manually resetting the colorbar's 'YTick' property after a call to cbarf.

30 Nov 2011 Christopher Wolfe

By the way, cbarf is otherwise great!

Please login to add a comment or rating.
Updates
17 Jul 2007

Added input argument SCALE for linear/non linear scale

14 May 2008

Corrected colors for the nonlinear case

Tag Activity for this File
Tag Applied By Date/Time
annotation M MA 22 Oct 2008 09:04:36
customization M MA 22 Oct 2008 09:04:36
colorbar M MA 22 Oct 2008 09:04:36
colorbarf M MA 22 Oct 2008 09:04:36
real M MA 22 Oct 2008 09:04:36
realistic M MA 22 Oct 2008 09:04:36
graphics M MA 22 Oct 2008 09:04:36
plot annotation M MA 22 Oct 2008 09:04:36
plot M MA 22 Oct 2008 09:04:36

Contact us at files@mathworks.com