1 |
|
---|
2 |
|
---|
3 |
function h=cplot(x,y,varargin) |
---|
4 |
%CPLOT colored linear plot |
---|
5 |
% CPLOT(X,Y,C) plots a line (Y vs. X) with the color specified by C. |
---|
6 |
% If X is a matrix, one line per column is created (Y&C should match its size then) |
---|
7 |
% Colors are interpolated according to current colormap & caxis. |
---|
8 |
% CPLOT(X,Y) is equivalent to CPLOT(X,Y,Y). |
---|
9 |
% CPLOT(...,linespec) specifies the style of the line used (cf. PLOT) |
---|
10 |
% all other parameters are passed to the PATCH object (e.g. MarkerSize, etc.) |
---|
11 |
% H=CPLOT(...) returns handle(s) of PATCH object. |
---|
12 |
% |
---|
13 |
% Example: cplot(-5:.1:5,cos(-5:.1:5)); |
---|
14 |
% |
---|
15 |
% Note: you can use ('edgecolor','interp'), but neither line thickness, |
---|
16 |
% nor line style will work (at least with Matlab 5.3Win) |
---|
17 |
% Note: PATCH objects are much slower than LINEs. Be patient with larger plots(~1e6 points) |
---|
18 |
|
---|
19 |
% 5/21/2001 ashcherbina@ucsd.edu |
---|
20 |
arg=varargin; |
---|
21 |
|
---|
22 |
if isempty(arg) | isstr(arg{1}) |
---|
23 |
c=y; |
---|
24 |
else |
---|
25 |
c=arg{1}; |
---|
26 |
arg={arg{2:end}}; |
---|
27 |
end |
---|
28 |
|
---|
29 |
% get the linestyle |
---|
30 |
line=[]; |
---|
31 |
marker=[]; |
---|
32 |
if ~isempty(arg) |
---|
33 |
% [line,marker]=lstyle(arg{1}); |
---|
34 |
if (~isempty(line) | ~isempty(marker)) |
---|
35 |
if length(arg)>1, |
---|
36 |
arg={arg{2:end}}; |
---|
37 |
else |
---|
38 |
arg={}; |
---|
39 |
end |
---|
40 |
end |
---|
41 |
end |
---|
42 |
if (isempty(line) & ~isempty(marker)) line='none'; |
---|
43 |
elseif (~isempty(line) & isempty(marker)) marker='none'; |
---|
44 |
elseif (isempty(line) & isempty(marker)) line='-';marker='none';end |
---|
45 |
|
---|
46 |
if any(size(x)==1) |
---|
47 |
|
---|
48 |
x=[x(:);nan]; |
---|
49 |
y=[y(:);nan]; |
---|
50 |
c=[c(:);nan]; |
---|
51 |
else |
---|
52 |
x=[x;x(1,:)*nan]; |
---|
53 |
y=[y;y(1,:)*nan]; |
---|
54 |
c=[c;c(1,:)*nan]; |
---|
55 |
end |
---|
56 |
|
---|
57 |
cax = newplot; |
---|
58 |
|
---|
59 |
hh=patch(x,y,0); |
---|
60 |
set(hh,'cdata',c,'LineStyle',line,'Marker',marker); |
---|
61 |
set(hh,'facecolor','none','edgecolor','flat'); |
---|
62 |
|
---|
63 |
if (~isempty(arg)) |
---|
64 |
set(hh,arg{:}); |
---|
65 |
end |
---|
66 |
|
---|
67 |
box on; |
---|
68 |
|
---|
69 |
if nargout>0, h=hh;end; |
---|