5.0

5.0 | 1 rating Rate this file 28 Downloads (last 30 days) File Size: 2.33 KB File ID: #39972
image thumbnail

colormapline - color-changing 2D or 3D line

by

 

25 Jan 2013 (Updated )

Plot a 2D or 3D line using a specified colormap.

| Watch this File

File Information
Description

% H = colormapline(X,Y,Z,C) Plot a line using a specified colormap
% If Z is given, a 3D plot with coordinates X, Y, Z is created.
% If Z is not given, a 2D plot of Y over X if created.
% If Y and Z are not given, a 2D plot of X over 1:length(X) is created.
% The plotted line uses all colors in a given colormap in ascending
% order. Other than with other functions in File Exchange, the color
% does NOT depend on any coordinate.
% Technically, length(colormap) lines are plotted, each with a different
% color from the colormap in ascending order.
% H is a handle to the complete colored line. It can be used to set
% parameters such as linewidth and linestyle.
% C is optional. If it is specified, it is used as a colormap. To use it
% with a 2D plot, use Z=[] and Y=[] if required;
%
% Examples:
%% 2D plot
% t=0:0.1:10*pi;
% h=colormapline(t.*sin(t),t.*cos(t),[],jet(128));
% set(h,'linewidth',3,'linestyle','--')
%
%% 3D plot
% t=-20*pi:0.1:20*pi;
% h=colormapline(t.*sin(t),t.*cos(t),sin(t),jet(128));
% set(h,'linewidth',3)
%
%% Minimal example (2D plot with one input)
% h=colormapline(1:1000);

% Changes from version 1 (2013-01-23):
% - Returns proper error messages when called
% with input vectors of length < 3 or with different lengths.
% - Exits with the same hold state it was started with.
% - Works with input vectors which are shorter than the colormap.
% For this, the colormap is compressed to the input vector length.
% - Works with colormaps of length 1 or 2
% - Also works with a single input, like plot(). (-> "minimal example")
% Thanks go to Rob Campbell for his comments on some of these points.

Other than stated below, this file was not inspired by by Matteo Niccoli's perceptually improved colormaps. Nevertheless I like them.

 

Acknowledgements

Perceptually Improved Colormaps inspired this file.

Required Products MATLAB
MATLAB release MATLAB 7.14 (R2012a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
14 Nov 2014 Matteo Niccoli

To get the lightness for jet in my previous snippet, I used this code:
lab2 = colorspace('RGB->Lab',jet(256));
and this submission:
http://www.mathworks.com/matlabcentral/fileexchange/28790-colorspace-transformations

14 Nov 2014 Matteo Niccoli

Works well for me. For eample I used this code:
figure;
j=jet(256);
h=colormapline(1:1:256,lab2(:,1),[],j);
set(h,'linewidth',2.5);
to get the first figure in this post:
http://mycarta.wordpress.com/2014/11/13/new-rainbow-colormap-sawthoot-shaped-lightness-profile/

Updates
29 Jan 2013

fixed small bugs and slightly enhanced the funtionality

Contact us