【发布时间】:2017-11-28 23:52:28
【问题描述】:
我正在使用类似以下命令来堆叠四组数据并在 matlab 中使用 bar3 绘制它们。如何为每组数据设置不同的颜色和图例?
下图。
figure(100);
for i=1:4
bar3(data.matrix{i})
hold on;
end
【问题讨论】:
标签: matlab colors stack legend
我正在使用类似以下命令来堆叠四组数据并在 matlab 中使用 bar3 绘制它们。如何为每组数据设置不同的颜色和图例?
下图。
figure(100);
for i=1:4
bar3(data.matrix{i})
hold on;
end
【问题讨论】:
标签: matlab colors stack legend
关于对每个条进行着色,解决方案是:
Y=[ 1 2 3 ; 4 5 6 ; 3 4 5];
h = bar3(Y);
cm = get(gcf,'colormap'); % Use the current colormap.
cnt = 0;
for jj = 1:length(h)
xd = get(h(jj),'xdata');
yd = get(h(jj),'ydata');
zd = get(h(jj),'zdata');
delete(h(jj))
idx = [0;find(all(isnan(xd),2))];
if jj == 1
S = zeros(length(h)*(length(idx)-1),1);
dv = floor(size(cm,1)/length(S));
end
for ii = 1:length(idx)-1
cnt = cnt + 1;
S(cnt) = surface(xd(idx(ii)+1:idx(ii+1)-1,:),...
yd(idx(ii)+1:idx(ii+1)-1,:),...
zd(idx(ii)+1:idx(ii+1)-1,:),...
'facecolor',cm((cnt-1)*dv+1,:));
end
end
rotate3d
source and additional information here
注意:关于 bar3 绘图的 Matlab 帮助是 here
【讨论】: