MATLAB Answers


How to make a colorbar for a Fill3 plot resembling surf

Baalzamon 님이 질문을 제출함. 12 Mar 2014
최근 활동 Baalzamon 님이 답변함. 12 Apr 2014
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,
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;

  댓글 수: 1

Can you post simple reproduction code and/or a screenshot?

로그인 to comment.

답변 수: 1

Baalzamon 님의 답변 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)));
This seems to work, if there are any problems with this approach please say why. Otherwise the thread can be closed.

  댓글 수: 0

로그인 to comment.

Translated by