Code covered by the BSD License  

Highlights from
COLORMAP and COLORBAR utilities (Sep 2009)

3.66667

3.7 | 6 ratings Rate this file 146 Downloads (last 30 days) File Size: 64.28 KB File ID: #24371
image thumbnail

COLORMAP and COLORBAR utilities (Sep 2009)

by Carlos Adrian Vargas Aguilera

 

08 Jun 2009 (Updated 30 Sep 2009)

MATLAB color utilities including COLORMAP join and interpolation; freeze and fit COLORBAR, etc.

| Watch this File

File Information
Description

These are some utilities that improve the COLORMAP and COLORBAR functions. They are as follows, and each one includes help and examples:
 
COLORMAP utilites:
cmapping - Colormap linear mapping/interpolation.
cmfit - Sets the COLORMAP and CAXIS to specific color bands.
cmjoin - Joins colormaps at certain levels.
cmlines - Change the color of plotted lines using the colormap.
 
COLORBAR utilities:
cbfit - Draws a colorbar with specific color bands between its ticks.
cbfreeze - Freezes the colormap of a colorbar.
cbhandle - Handle of current colorbar axes.
cblabel - Adds a label to the colorbar.
cbunits - Adds units to the colorbar ticklabels.

I include updated versions of the following functions I submitted here previously:
SETCOLORMAPS (now called CMJOIN),
COLORBARFIT (now called CBFIT),
CBLABEL and
CBUNITS.

Enjoy it!
Bugs reports and suggestions will be very appreciated!

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
usercolormap, freezeColors / unfreezeColors, imagescnan.m v2.1 (Aug 2009), CMAPLINE, real2rgb & colormaps
This submission has inspired the following:
quiver2.m v1.2 (Nov 2009)

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (16)
27 Jun 2009 Carlos Adrian Vargas Aguilera

There is a little bug on CMAPPING. Magenta 'm' color is colored as red 'r' in v1.0. Well...

Carlos

21 Aug 2009 David

Hello!

I use cbfreeze in combination with freezeColor and got exactly what I need!!!

THANK YOU!

David

21 Aug 2009 David  
25 Aug 2009 Andrea

Hi everyone, I've got a problem: when I use the function cmapping in the command line it works, but when I try to use it in a GUI there are no errors, but the function does nothing, please help me.

18 Jul 2010 Lachlan Hennessy

cbfreeze does not seem to support log scale colorbars. I have been having some trouble with creating a contourf plot with a logarithmic scale and colorbar. I was hoping that this could be treated in a future update.

Thank you

22 Oct 2010 David Verrelli

I have the same problem as Lachlan Hennessy.
See
http://www.mathworks.com/support/solutions/en/data/1-16X5V/?solution=1-16X5V
and
http://www.mathworks.com/support/solutions/en/data/1-2H5IF9/?solution=1-2H5IF9
They might help.
The latter looks like a slightly more elegant solution, but I can't get it to work, at least with surf. I suspect the only way is the clunky workaround of the first link. Or to dig around inside the colorbar function itself.
—DIV

22 Oct 2010 David Verrelli

Re. my previous post, Solution ID: 1-16X5V does seem to work, and is in fact more elegant than I'd given it credit for.

A more complete example, with a practical application to surface plots (rather than just displaying a raster image) is as follows:
==BEGIN CODE==
[X,Y,D] = peaks;
% D is your 'elevation' data

% Rescale data 1-64
%d = log10(D);
d = real( log10(D) );
mn = min(min(d));
rng = max(max(d))-mn;
d = 1+63*(d-mn)/rng; % Self scale data
%image(d);
surf(d)
hC = colorbar;

LInput = -10:10;
L = 10.^LInput;
% Choose appropriate
% or somehow auto generate colorbar labels
l = 1+63*(log10(L)-mn)/rng; % Tick mark positions
set(hC,'Ytick',l,'YTicklabel',L);
set(gca,'Ztick',l,'ZTicklabel',L);
==END CODE==

This seems to work. The main problem is that the input data goes negative, but that is not a fault of the method per se.

—DIV

26 Oct 2010 David Verrelli

As I explore this further, I note another problem with the foregoing code:
while the colour scale is logarithmic, as desired, the scale on the z-axis is also logarithmic, which MAY or MAY NOT be desired.

—DIV

19 Nov 2010 Matthias Pospiech

It does not work for me. I have two pcolor plots. If I use cbfreeze the colorbar is displaced with comlete different position values and overlapps with the second pcolor plot. The colorbar is saved, but the first pcolor plot still has the colors of the second pcolor plot. So in result everything looks messed up and the colors of the plots are not saved.

On request I can submit the plot file for testing/debugging.

20 Nov 2010 Makarand

There is little bug in cbfreeze. If we have a label to colorbar the lable vanishes after use of cbfreeze and thickness increases.
looking forward for reply

20 Jan 2011 Ines

Dear Makarand,

I had the same issue, but managed a workaround, which hopefully works for you too.
First I control the colorbar position options so that the it is located slightly farther from the image, and looks much thinner than I want it to be; when I call cbfreeze, the command won't thicken it too much. Regarding the colorbar label, I add it at the very last moment, by deciding its location with [a,b]=ginput, and then writing it with text(a,b,'color_label').

Inès

02 Feb 2011 Andris  
08 Jul 2011 Leslie  
20 Nov 2011 Ian Colon

It does not work for me. I keep getting an error:
??? Undefined function or method 'cbhandle' for input arguments of type
'double'.

23 Nov 2011 craq

I had the same problem as Ines and Makarand, but I used a different solution. It might even be possible to include this in cbfreeze.m

I apply cbfreeze before the label, then the width doesn't change. After adding a second axis with a second colorbar, I find the handle to the old colorbar (as the only unknown colorbar handle) and then put the label on.

colorbarHandles=findobj(gcf,'Tag','Colorbar')
for i=1:length(colorbarHandles)
    if colorbarHandles(i)~=cBarAxis2
        cBarAxis1=colorbarHandles(i);
    end
end
ylabel(cBarAxis1,'my label')

30 Nov 2011 MrSeniorLoveDaddy

Good job, thank you.
IAN COLON, try to insert the file cbhandle in your working directory.

Please login to add a comment or rating.
Updates
30 Jun 2009

Fixed small bug with 'm' magenta color on CMAPPING. Added files versions on Contents.m

20 Aug 2009

Fixed bug in CBHANDLE with colorbar handle input

02 Sep 2009

Fixed BUGs on CBFREEZE (thanks to Sergio Muniz) and CMAPPING (thanks to Andrea Rumazza).

30 Sep 2009

Fixed some bugs on CBUNITS and CBFIT.

Tag Activity for this File
Tag Applied By Date/Time
color Carlos Adrian Vargas Aguilera 08 Jun 2009 15:41:47
caxis Carlos Adrian Vargas Aguilera 08 Jun 2009 15:41:47
colormap Carlos Adrian Vargas Aguilera 08 Jun 2009 15:41:47
colorbar Carlos Adrian Vargas Aguilera 08 Jun 2009 15:41:47
colormapeditor Carlos Adrian Vargas Aguilera 08 Jun 2009 15:41:47
setcolormaps Carlos Adrian Vargas Aguilera 08 Jun 2009 15:41:47
color freeze Carlos Adrian Vargas Aguilera 08 Jun 2009 15:41:47
colorbarfit Carlos Adrian Vargas Aguilera 08 Jun 2009 15:41:47
rgb Carlos Adrian Vargas Aguilera 08 Jun 2009 15:41:48
color interpolation Carlos Adrian Vargas Aguilera 08 Jun 2009 15:41:48
color mapping Carlos Adrian Vargas Aguilera 08 Jun 2009 15:41:48
cmapping Carlos Adrian Vargas Aguilera 01 Jul 2009 11:32:35
colorbarfit Rinku 06 Sep 2011 21:15:04

Contact us at files@mathworks.com