Code covered by the BSD License  

Highlights from
cline

5.0

5.0 | 4 ratings Rate this file 33 Downloads (last 30 days) File Size: 8.38 KB File ID: #14677
image thumbnail

cline

by Sebastian Hölz

 

16 Apr 2007 (Updated 16 Apr 2007)

Draw a colored line in 2D or 3D

| Watch this File

File Information
Description

There are several files on the FEX which deal with the plotting of colored lines, but they all have some drawbacks. I wrote a little file, which extends the scope of the submission by Kun Liu (s. below, hoping to deliver a general purpose file, which should work for most purposes.

SYNTAX
======
h = cline(x, y [, z, cdata])

INPUT
=====
x: vector with x-values
y: vector with y-values
z (opt.): vector with z-values
cdata (opt.): vector with color-data

2 input arguments => cdata = y; z=0
3 input arguments => cdata = z
4 i.a. & z = [] => cdata = y; z=0

OUPUT
=====
h: Handle to line (i.e. patch-object !!!)

Examples
========
t = 2*pi:.1:8*pi;

cline(sqrt(t).*sin(t), sqrt(t).*cos(t));
cline(sqrt(t).*sin(t), sqrt(t).*cos(t), t);
cline(sqrt(t).*sin(t), sqrt(t).*cos(t), t, rand(size(t))); view(3)
cline(sqrt(t).*sin(t), sqrt(t).*cos(t), [], rand(size(t))); view(3)

OK, hope you find this file useful

Sebastian

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Linear 2D Plot with Rainbow Color
This submission has inspired the following:
Perceptually improved colormaps

MATLAB release MATLAB 7.0.4 (R14SP2)
Other requirements none
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (7)
26 Jun 2007 Matt Bennett  
19 Feb 2010 Xavi Alonso

it doesn't work for me when cdata is a matrix

12 Oct 2010 Sean Torrez

Beautiful file, thanks a bunch. Quite simple, works well.

15 Oct 2010 Matteo Niccoli

This is really a great submission. I can think of vaery many ways of using it.

For starters, in conjunction with Colorspace transforamtions
( www.mathworks.com/matlabcentral/fileexchange/28790-colorspace-transformations ) I used it for an example in my Perceptually improved colormaps submission. I used cline this way:

% J=jet(256);
% LJ=colorspace('RGB->Lab',J);
% figure; cline([1:1:256],LJ(:,1),LJ(:,1),[1:1:256],J);
% title ('L* plot for jet colormap','Color','k','FontSize',12);

Also, as I was reading Steve's post on Lab based colormaps (thank you Steve!), I used cline this way to help me visualize things (notice again I used colorspace):

% radius = 50;
% theta = linspace(0, pi/2, 256).';
% a = radius * cos(theta);
% b = radius * sin(theta);
% L = linspace(0, 100, 256).';
% Lab = [L, a, b];
% RGBhlx=colorspace('RGB<-Lab',(Lab));
% figure; cline(a, b, L, L,RGBhlx); view(3);
% VIEW(-165,-15);

05 May 2011 Natasha

Great, works perfectly, thanks

06 May 2011 Jaap

Thanks for the post, I find it very useful. Do you perhaps know a way to increase the thickness of the line? Adding filled circular patch markers does do something, but the markersize makes a very sharp transition at 4.8-4.9.

12 May 2011 Sebastian Hölz

@Jaap:

Use the following syntax:

fig = figure;
h = cline(...);
set(h,'linewidth',5)

The increased line-width will not be displayed, if you use "painters" as renderer for your figure. Therefore, you will have to change it:

set(fig, 'renderer', 'zbuffer')

- or -

set(fig, 'renderer', 'opengl')

Cheers

Sebastian

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
specialized Sebastian Hölz 22 Oct 2008 09:09:42
plotting Sebastian Hölz 22 Oct 2008 09:09:42
line Sebastian Hölz 22 Oct 2008 09:09:42
2d Sebastian Hölz 22 Oct 2008 09:09:42
3d Sebastian Hölz 22 Oct 2008 09:09:42
colored Sebastian Hölz 22 Oct 2008 09:09:42
graphics Sebastian Hölz 22 Oct 2008 09:09:42

Contact us at files@mathworks.com