2017-07-22 21 views
1

Matlabで3D棒グラフを作成しました。私は、各グループのために同じ色たい(例えば、S1 =青、S2 =緑色およびS3 =赤、以下のグラフを参照)Matlabのbar3プロットのグループの色を制御する方法

Iは、次のコード使用:任意の提案

Z = data; 
Y = [1 300 600]; % The positions of bars along the y axis 
h = bar3(Y,Z',0.05); 
[nGroup, nBar] = size(Z); 
nColors = size(get(gcf, 'colormap'), 1); 
colorInd = randi(nColors, nBar, nGroup); 
for i = 1:nGroup 
    c  = get(h(i), 'CData'); 
    color = repelem(repmat(colorInd(:, i), 1, 4), 6, 1); 
    set(h(i), 'CData', color); 
end 
set(gca, 'YTickLabel', 

か?

enter image description here

答えて

0

代わりのy軸によってグループを設定し、x軸によってそれらを設定するので、各グループは1つのグラフィックオブジェクトであり、完全に着色することができます。ここ は、これを行うための簡単な方法です:

Z = randi(7,11,3); % some data with three groups 
bar3(Z,0.05); % Each column in Z is one graphic object 
set(gca,'XTickLabel',{'s1' 's2' 's3'}); % set the lables of the groups 
set(gca,'PlotBoxAspectRatioMode','auto') % make the view wider 
set(gca,'YDir','normal') % reverse the y-axis to match your example 
colormap(lines(3)) % define 3 colors for coloring by group 
view(55,22) % rotate the orintation to match your example 

bar3

、あなたの質問に色をしたい場合は、あなたとカラーマップを置き換えることができます。

colormap(flipud(eye(3))) 

やタイプ:

h = bar3(Z,0.05); % instead of bar3(Z,0.05) 
set(h,{'FaceColor'},{[0 0 1];[0 1 0];[1 0 0]}) 
関連する問題