How to make a colorbar for a Fill3 plot resembling surf

2 views (last 30 days)
So previously I asked about making a surf style plot with the center of the square being the point of interest as oppose to using the vertices, I was informed of making patch objects etc. Now I have created the figure I wanted but using the fill3 function and used a color scale corresponding to the height of the data point. My problem now is that I need a colorbar. The standard colorbar produces incorrect results in that the labels do not correspond to the range of the input data.
Will I have to mechanically tell colorbar to make the tick values at a1,a2,...az?
Thanks
The first four lines simply get ranges for my zdata and makes a vector to be used to find the colour needed. The loop is unimportant and the dx and dy is to ensure the correct size square. I have got three pics to see, (1) the plot in the x-y plane, (2) the same plot in y-z plane - to show the colorbar is wrong (3) screen shot showing the colorbar is black on my screen but not when I save the figure
minZ = min(b(:,18));maxZ = max(b(:,18));
ZZ = (round(minZ*10000):round(maxZ*10000))/10000;
lengthZ = numel(ZZ);
CC = jet(lengthZ);
for ii = 1:numel(b(:,1))
gridclr = CC(ZZ==b(ii,18),:);
p1 = [b(ii,13)-dx b(ii,16)-dy b(ii,18)];
p2 = [b(ii,13)+dx b(ii,16)-dy b(ii,18)];
p3 = [b(ii,13)+dx b(ii,16)+dy b(ii,18)];
p4 = [b(ii,13)-dx b(ii,16)+dy b(ii,18)];
x = [p1(1) p2(1) p3(1) p4(1)];
y = [p1(2) p2(2) p3(2) p4(2)];
z = [p1(3) p2(3) p3(3) p4(3)];
fill3(x, y, z,gridclr);
hold on;
end;

Answers (1)

Baalzamon
Baalzamon on 12 Apr 2014
So, I compared my plot (using fill3) to the similar plot with surf with the get() function and noticed that my cdata is empty and my zdata is only retained for the most recent data points.
I then used the set() command to dummy in a fake cdata array and now I get the colorbar and with the correct limits. dmy=linspace(min(b(:,18)),max(b(:,18)),numel(b(:,18)));
set(hp1,'cdata',dmy);
This seems to work, if there are any problems with this approach please say why. Otherwise the thread can be closed.
Thanks.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!