File Exchange

image thumbnail

CMAPLINE

version 1.2 (2.5 KB) by

apply a colormap to lines in a plot

4.33333
3 Ratings

5 Downloads

Updated

View License

CMAPLINE finds all lines in an axis and specifies their colors according to a colormap. Also accepts custom colormaps in the form of a n x 3 matrix.

EXAMPLE (generates screenshot)

%generate some data
x=(0:0.1:2*pi);
m=50; exdata=bsxfun(@plus,repmat(25.*sin(x),...
[m 1]),[1:m]');

figure
subplot(121);
plot(x,exdata,'o-','linewidth',2)
cmapline('colormap','jet');
set(gca,'color','k')
title('jet colormap')

subplot(122);
plot(x,exdata,'o-','linewidth',2)
custommap=flipud(hot);
cmapline('colormap',custommap,'filled')
set(gca,'color','k')
title('reverse hot colormap, filled markers')

Comments and Ratings (6)

Carl

Carl (view profile)

Does what it says on the box. Very handy. Thanks!

Stefano

If used with the 'lines' option, cmaplines returns an error if the linehandles are supplied as row vector. This can be avoided by changing line 152

cellfun(@(x,y)(set(x,'color',y)),lh(:),colrs);

Ryan Ollos

@ Carlos: "I think this was the idea of VARYCOLOR, but it missed it."

I don't see this as being the case. The purpose of VARYCOLOR is to create a colormap with maximum color variation. The purpose of this function seems to be applying a colormap to lines in an axes. They seem to have completely different purposes.

Andrew Stevens

Carlos, thanks for your comments. I recently updated the file to incorporate your suggestions (though my handling of input arguements is still a bit crude).

Carlos Adrian Vargas Aguilera

I think this was the idea of VARYCOLOR, but it missed it. Andrew, it would be nice to have the handle lines as an optional input. An a question: Why gcf is an specified axes handle? An idea could be:
>> CMAPLINE
>> CMAPLINE(COLORMAP) % string or hfunction or Mx3
>> CMAPLINE(AH,...) % single axes handle or
>> CMAPLINE(LH,...) % line handles (1 or more)

Well done, Carlos

Updates

1.2

updated help so that the example will run properly, description

add handle of line objects as optional output, as suggested by Carlos.

added capability of filling markers, updated help

MATLAB Release
MATLAB 7.6 (R2008a)
Acknowledgements

Inspired by: varycolor

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video