View License

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

» Watch video

Highlights from

4.3 | 3 ratings Rate this file 8 Downloads (last 30 days) File Size: 2.5 KB File ID: #21102 Version: 1.2
image thumbnail



Andrew Stevens (view profile)


15 Aug 2008 (Updated )

apply a colormap to lines in a plot

| Watch this File

File Information

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
m=50; exdata=bsxfun(@plus,repmat(25.*sin(x),...
[m 1]),[1:m]');

title('jet colormap')
title('reverse hot colormap, filled markers')


Varycolor inspired this file.

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (6)
15 Jun 2016 Carl

Carl (view profile)

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

10 Mar 2012 Stefano

21 Jul 2011 Wolfgang Schwanghart

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


Comment only
29 Nov 2008 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.

Comment only
16 Sep 2008 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).

Comment only
20 Aug 2008 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(COLORMAP) % string or hfunction or Mx3
>> CMAPLINE(AH,...) % single axes handle or
>> CMAPLINE(LH,...) % line handles (1 or more)

Well done, Carlos

16 Sep 2008

added capability of filling markers, updated help

16 Sep 2008

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

29 Oct 2008 1.2

updated help so that the example will run properly, description

Contact us