-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot3c.m
More file actions
144 lines (119 loc) · 3.08 KB
/
Copy pathplot3c.m
File metadata and controls
144 lines (119 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
function [h,ch]=plot3c(varargin)
% A 2d scatter plot to display 3d data, with the color of each point
% indicating the third dimension. Requires x,y,z data and a value "c" to
% show how many linearly spaced colour bins required. Otherwise a vector
% can be given, containing the edges of the colour bins. If a vector is
% used and is padded by a single nan's, the nan's will be replaced by the
% min and max value of z.
%
% This is the first function I've written to accept parameter and and value
% pairs to allow properties of the plot to be changed.
%
% Hard coded into this is colormap, marker, markersize and linestyle, with
% defaults being jet, '.', 4, and 'none'
%
% Jonathan Tinker 14/06/06
%
% e.g.
% x=rand(100,1)
% y=sin(x)
% z=cos(x)
% c=10;
%
% [h,ch]=plot3c(x,y,z,c)
if nargin<3
disp('Insufficient input variables, needs x,y,z')
return
else
x=varargin{1};
y=varargin{2};
z=varargin{3};
end
if nargin==3
c=linspace(min(z),max(z),6)
else
c=varargin{4};
end
if logical(((nargin/2-floor(nargin/2))*2)==1)&(nargin>3)
disp('Parameter and values must be paired')
end
if length(c)==1
n=c;
minz=min(z);
maxz=max(z);
zedges=linspace(minz,maxz,n+1);
else
zedges=c;
if ~isempty(z)
if isnan(zedges(1))
zedges(1)=min(z);
end
if isnan(zedges(end))
zedges(end)=max(z)+eps;
end
else
if isnan(zedges(1))
zedges(1)=zedges(1)-1;
end
if isnan(zedges(end))
zedges(1)=zedges(end)+1+eps;
end
end
end
cnt=1;
zlabel='';
for i=5:2:length(varargin)
if strcmp(varargin{i},'colormap')
C=colormap(varargin{i+1});
elseif strcmp(varargin{i},'markersize')
mksz=varargin{i+1};
elseif strcmp(varargin{i},'marker')
mk=varargin{i+1}
elseif strcmp(varargin{i},'linestyle')
linsty=varargin{i+1};
elseif strcmp(varargin{i},'zlabel')
zlabel=varargin{i+1};
else
param{cnt}=varargin{i};
value{cnt}=varargin{i+1};
end
cnt=cnt+1;
end
if exist('C')~=1
C=colormap;
end
if exist('mksz')==0
mksz=4;
end
if exist('mk')==0
mk='.';
end
if exist('linsty')==0
linsty='none';
end
zpnts=mean([zedges(1:end-1)' zedges(2:end)' ]');
cpnts=sort([zedges zpnts])';
c=C(round(linspace(1,64,length(cpnts))),:);
c=c(2:2:end,:);
hold on
for i=1:length(zedges)-1
ind=(z>=zedges(i))&(z<zedges(i+1));
tmph=plot(x(ind),y(ind),'color',c(i,:),'markersize',mksz,'marker',mk,'linestyle',linsty);
if ~isempty(tmph)
h(i)=tmph;
else
h(i)=nan;
end
end
if exist('param')~=0
for i=1:length(param)
set(gca,param{1},value{i})
end
end
caxis([zedges(1) zedges(end)])
ch=colorbar;
clabs=num2str(cpnts);
clabs(2:2:end,:)=' ';
set(ch,'ytick',cpnts,'YTickLabel',clabs)
set(get(ch,'ylabel'),'string',zlabel)
hold off