2017-06-26 8 views
-1

私は4つのデータセットを積み重ね、それらをmatlabのbar3を使ってプロットするために、次のコマンドのようなものを使用しています。データのスタックごとに異なる色と凡例を設定するにはどうすればよいですか?bar3の色と凡例

以下の添付図。

figure(100); 

for i=1:4 
    bar3(data.matrix{i}) 
    hold on; 
end 

figure

答えて

0

各バーをカラー化について、解決策は次のようになります。

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

です
関連する問題