2017-06-26 9 views
-1

Ich verwende etwas wie die folgenden Befehle, um vier Datensätze zu stapeln und sie mit Hilfe von bar3 in Matlab zu plotten. Wie kann ich für jeden Datenstapel eine andere Farbe und Legende festlegen?Farbe und Legende in bar3 Matlab

Abbildung unten angehängt.

figure(100); 

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

figure

Antwort

0

Über jede Bar Einfärben, wäre die Lösung:

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

Hinweis: Matlab-Hilfe auf bar3 Plots ist here

Verwandte Themen