Code covered by the BSD License  

Highlights from
CMAPLINE

4.0

4.0 | 1 rating Rate this file 11 Downloads (last 30 days) File Size: 2.5 KB File ID: #21102
image thumbnail

CMAPLINE

by Andrew Stevens

 

15 Aug 2008 (Updated 29 Oct 2008)

apply a colormap to lines in a plot

| Watch this File

File Information
Description

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')

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
varycolor
This submission has inspired the following:
COLORMAP and COLORBAR utilities (Sep 2009)

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
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
>> 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 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).

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.

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

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

Please login to add a comment or rating.
Updates
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

updated help so that the example will run properly, description

Tag Activity for this File
Tag Applied By Date/Time
specialized Andrew Stevens 22 Oct 2008 10:14:54
plotting Andrew Stevens 22 Oct 2008 10:14:54
colormap Andrew Stevens 22 Oct 2008 10:14:54
lines Andrew Stevens 22 Oct 2008 10:14:54
specialized plot Andrew Stevens 22 Oct 2008 10:14:54
graph types Andrew Stevens 22 Oct 2008 10:14:54
graphics Andrew Stevens 22 Oct 2008 10:14:54
colormap Filippo 14 Jan 2011 10:50:11
lines Philippe 18 Feb 2011 16:17:57

Contact us at files@mathworks.com