Code covered by the BSD License  

Highlights from
colorbarf

4.22222

4.2 | 9 ratings Rate this file 25 Downloads (last 30 days) File Size: 4.39 KB File ID: #1135
image thumbnail

colorbarf

by Blair Greenan

 

06 Dec 2001 (Updated 04 Apr 2006)

Add an accurate colorbar to your filled contour plot.

Editor's Notes:

This file was a File Exchange Pick of the Week

| Watch this File

File Information
Description

This m-file produces a colorbar with solid blocks of color between the contour levels that correspond precisely to the colors in the filled contour plot. This is in contrast to the standard MATLAB colorbar which simply plots all the colors in the colormap and, therefore, only approximates what is being plotted in the filled contour plot.

Acknowledgements
This submission has inspired the following:
cbarf
MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (12)
05 May 2002 Mads Hvid Nielsen  
14 Mar 2003 Nikolaos Skaropoulos  
03 Feb 2004 Robert Weinmann

Very good.

30 Jul 2004 Felix Jose

Very handy and expressive for presentations

25 Mar 2005 r pearson

This program was not working when I downloaded it. I would get the error:
Error in ==> colorbarf at 151
   colors(j) = get(H(j),'CData'); % get the color used to fill the
patches
This was with version 7 even if I used the 'v6' option.
I made these changes and it works now:
%Modded by R Pearson
for j = 1:length(H)
% colors(j)= get(H(j),'CData'); % get the color used to fill the patches
   tempcolors = get(H(j),'CData'); % get the color used to fill the patches
   colors(j)=tempcolors(1,1)
end
%%%%%End Pearson

I worked after this but I don't know if it is the right way to do this. I don't endorse this method at all. It simply works for me in my limited usage.

14 Apr 2005 Dan S

Can this utility be modified to work with the surf function?

I need a color bar on a surface plot but the scale on the built in colorbar is inaccurate since it's divided into 64 segments instead of the 5 integer divisions that I need.

19 Oct 2005 Jean-Marie Ndambi  
04 Feb 2008 Alan Drew

Every time I plot a slightly different subset of my array (e.g from contourf(y(50:150),x(50:150),positron(50:150,50:150)) to contourf(y(70:130),x(70:130),positron(70:130,70:130)) ) the axis get smaller but the colorbarf remains the same size. As a consequence, if I am optimising the display of my figure, I have to keep closing the figure window.

09 May 2008 onur kerimoglu

Exactly what I was looking for. I don't understand why it was not built-in. Thanks.

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.

14 May 2010 Shannon Fargey

can colourbarf be used with pcolor instead of contourf? if so what modifications would have to be made?

29 Jan 2012 Albert Drif

does it support log scale? Like colorbar('Yscale','log')? I know I can convert the data to log10 first, but the ticks of colorbarf becomes -2 -1 0 1 2, which I want it display as 10^{-2} 10^{-1} 10^{0} 10^{1} 10^{2}, like in Latex. Thx

Please login to add a comment or rating.
Updates
05 Aug 2004

Updated to be compatible with MATLAB 7

04 Apr 2006

Updated for better compatibility with MATLAB 7

Tag Activity for this File
Tag Applied By Date/Time
annotation Blair Greenan 22 Oct 2008 06:39:43
customization Blair Greenan 22 Oct 2008 06:39:43
colorbar Blair Greenan 22 Oct 2008 06:39:43
filled Blair Greenan 22 Oct 2008 06:39:43
contour Blair Greenan 22 Oct 2008 06:39:43
graphics Blair Greenan 22 Oct 2008 06:39:43

Contact us at files@mathworks.com